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 operators_and_non_operators(s, operator_list): | |
"""returns the non-operators | |
>>> operators_and_non_operators('2*3+3-4', ['+', '-']) | |
(['+', '-'], ['2*3', '3', '4']) | |
""" | |
ops = [] | |
non_ops = [] | |
current_non_op = '' | |
for c in s: |
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
""" | |
Example app: | |
from framework import server, add_route | |
def home(): | |
return "<html>Hello!</html>" | |
add_route('/', home) | |
server.serve_forever() |
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 re | |
class Tokens(): | |
def __init__(self, s): | |
self.tokens = tokenize(s) | |
self.current_i = 0 | |
def peek(self): | |
return self.tokens[self.current_i] | |
def consume(self): | |
t = self.tokens[self.current_i] |
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 itertools | |
def brute(): | |
for candidate in itertools.permutations(range(8)): | |
if (len(set(x - y for x, y in enumerate(candidate))) == 8 and | |
len(set(x + y for x, y in enumerate(candidate))) == 8): | |
yield candidate | |
def ordinals(): | |
opposite_of_teenager = ["th", "st", "nd", "rd"] + ["th"] * 6 |
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
public class Node { | |
public Node left; | |
public Node right; | |
public int value; | |
public Node(int value, Node left, Node right){ | |
this.value = value; | |
this.left = left; |
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
require 'rspec' | |
require 'forwardable' | |
require 'pry' | |
require 'set' | |
class ListyThing | |
extend Forwardable | |
def_delegators :@data, :<<, :empty?, :concat | |
def initialize | |
@data = [] |
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
##Brian Chesley, Connect 4 | |
def run(): | |
board = [] | |
for i in range(0,6): | |
board.append([0]*7) | |
for row in board: | |
print row | |
turn = 1 | |
p1_wins = False |
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 socket | |
def serve(): | |
listener = socket.socket() | |
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
listener.bind(('', 8080)) | |
listener.listen(5) | |
while True: | |
s, addr = listener.accept() | |
request = s.recv(10000) |
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 socket | |
# see wsgiref.simple_server for a real implementation of a WSGI server | |
def serve(app): | |
listener = socket.socket() | |
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
listener.bind(('', 8080)) | |
listener.listen(5) | |
while True: | |
s, addr = listener.accept() |
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 sys | |
import urllib | |
import webbrowser | |
def get_opt_url(s, from_bpython=True): | |
""" Use json to post to github. """ | |
def fix(text): |
OlderNewer