This file contains hidden or 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 json | |
| def walkjson(json): | |
| tree = [] | |
| if isinstance(json, dict): | |
| for key in json.keys(): | |
| value = json[key] | |
| tree.append(key) | |
| tree.append(walkjson(value)) |
This file contains hidden or 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 avg_speed(distance_in_miles, time_in_minutes): | |
| time_in_hrs = time_in_minutes/60.0 | |
| return float(distance_in_miles)/float(time_in_hrs) | |
| def river_sprint(avg_mph, river_distance=4.5): | |
| """ | |
| Return the time it would take (in minutes) to | |
| sprint the river at speed given by avg_mph. | |
| """ | |
| return (float(river_distance)/float(avg_mph))*60 |
This file contains hidden or 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 serial | |
| import serial.tools.list_ports as list_ports | |
| def autodetect(): | |
| disconnected = True | |
| while disconnected: | |
| ports = list(list_ports.comports()) | |
| # Identify correct port ... somehow |
This file contains hidden or 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 logging | |
| def create_logger(self): | |
| # See https://wingware.com/psupport/python-manual/2.3/lib/node304.html | |
| logger = logging.getLogger(self.name) | |
| hdlr = logging.FileHandler(self.logfile) | |
| formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') | |
| hdlr.setFormatter(formatter) | |
| logger.addHandler(hdlr) | |
| logger.setLevel(logging.DEBUG) |
This file contains hidden or 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
| """ Generator-based versions of tokenize and read_from_tokens from Norving's "How to write a Lisp Interpreter in Python" """ | |
| from itertools import takewhile | |
| def tokenize(chars): | |
| ''' Convert a string expression into a generator of tokens. ''' | |
| return (t for t in chars.replace('(', ' ( ').replace(')', ' ) ').split()) | |
| def read_from_tokens_gen(tokens, current_token=None): |
This file contains hidden or 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
| # -*- coding: utf-8 -*- | |
| from parsimonious.grammar import Grammar | |
| try: | |
| from string import lowercase | |
| except: | |
| from string import ascii_lowercase as lowercase | |
| def vars_expr(): |
This file contains hidden or 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 find_matching_node(expr, matching_fn, parent_node=None, parent_rel=None): | |
| if isinstance(expr, Expression) and matching_fn(expr): | |
| return (expr, parent_node, parent_rel) | |
| if isinstance(expr, Term): | |
| return | |
| left_match = find_matching_node(expr.left, parent_node=expr, parent_rel='left') | |
| right_match = find_matching_node(expr.right, parent_node=expr, parent_rel='right') | |
| if left_match: |
This file contains hidden or 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 copy import deepcopy | |
| class ClausePair: | |
| def __init__(self, c1_set, c2_set): | |
| self.c1, self.c2 = frozenset(c1_set), frozenset(c2_set) | |
| def __eq__(self, other): | |
| if isinstance(other, self.__class__): | |
| return ((self.c1 == other.c1 and self.c2 == other.c2) or |
This file contains hidden or 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
| TIILE: gForth Overiew | |
| ORIG DATE: 20170930 | |
| LAST REV DATE: 20170930 | |
| AUTHOR: mj <modusjonens@gmail.com> | |
| ========================================================== | |
| $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ | |
| ========================================================== | |
This file contains hidden or 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
| class Stack | |
| def initialize | |
| @contents = [] of Int32 | |
| end | |
| def pop | |
| @contents.pop() | |
| end | |
| def push(value) |