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
""" 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
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
#!/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
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
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
supervisord [supervisord.org] | |
============================= | |
* Set up jobs via a config file (.ini style) | |
Example: | |
-------- | |
[program:forever] | |
command=/usr/bin/python /root/supervisoreval/bin/forever.py & | |
numprocs=1 |
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 Adapter: | |
def __init__(self, object, **adapted_method): | |
self.object = object | |
self.__dict__.update(adapted_method) | |
def __getattr__(self, attr): | |
return getattr(self.object, attr) |
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
PLAY [create vpn server] ****************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [localhost] | |
TASK: [create-droplet | ensure dopy is installed (for digitalocean API)] ****** | |
ok: [localhost] | |
TASK: [create-droplet | create digitalocean droplet] ************************** | |
ok: [localhost] |
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
PLAY [create vpn server] ****************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [localhost] | |
TASK: [create-droplet | ensure dopy is installed (for digitalocean API)] ****** | |
ok: [localhost] | |
TASK: [create-droplet | create digitalocean droplet] ************************** | |
ok: [localhost] |