Skip to content

Instantly share code, notes, and snippets.

View newsch's full-sized avatar

Evan Lloyd New-Schmidt newsch

View GitHub Profile
#!/usr/bin/env python3
import sys
import logging
def main():
fname = sys.argv[1]
with open(fname) as f:
blob = f.read()
pairs = blob.split(',')
@newsch
newsch / .gitignore
Last active May 30, 2019 23:21
Exploring text compression approaches
cache.html
__pycache__/
.ipynb_checkpoints/
#!/usr/bin/env python3
"""Format a csv-styled 9x9 sudoku board.
Usage: `sudoku -g -fcsv | ./receipt-sudoku.py - > receipt.txt
"""
from typing import List
SudokuBoard = List[List[int]]
$0=10 (Step pulse time, microseconds)
$1=25 (Step idle delay, milliseconds)
$2=0 (Step pulse invert, mask)
$3=0 (Step direction invert, mask)
$4=0 (Invert step enable pin, boolean)
$5=1 (Invert limit pins, boolean)
$6=0 (Invert probe pin, boolean)
$10=1 (Status report options, mask)
$11=0.010 (Junction deviation, millimeters)
$12=0.002 (Arc tolerance, millimeters)
import serial
import time
DEVICE_PATH = '/dev/ttyACM0'
BAUD_RATE = 115200
s = serial.Serial(DEVICE_PATH, BAUD_RATE)
while True:
if s.in_waiting > 0: # when new serial info is waiting
#!/usr/bin/env python3
"""Print a horizontal or vertical enumeration.
Need to figure out how many characters tall or wide something is in a pinch?
This is the commandline utility for you!
"""
import argparse
parser = argparse.ArgumentParser(
description='Print a horizontal or vertical enumeration.')
@newsch
newsch / centerer.py
Last active May 12, 2019 03:46
Commandline script to center text
#!/usr/bin/env python3
"""Commandline script to center text horizontally."""
import argparse
def center(line: str, width: int, length: int = None):
"""Center a line within a width, optionally treating it as len length.
>>> center('foo', 6)
' foo'
@newsch
newsch / group_parser.py
Created September 19, 2018 02:52
Parse a csv of Olin student groups and output formatted text.
#!/usr/bin/env python3
import csv
with open('groups.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile, ['full','acrnm','leader'])
names = [club['acrnm'] if club['acrnm'] != '' else club['full'] for club in reader]
[print(name) for name in names]
@newsch
newsch / focsuml.py
Last active September 18, 2018 04:54
Convert an abacus-style computation diagram into a plantUML diagram
#!/usr/bin/env python3
"""Convert an abacus-style computation diagram into a plantUML diagram
https://regexr.com/3vj09
"""
import argparse
import re
import warnings
parser = argparse.ArgumentParser(description='Generate PlantUML activity diagrams from FoCS abacus-style diagram lists.')
/*******************************************************************************
* Step 0) Add a clear descriptive title block at the top of your robot code
* Example Title block follows:
* Title: 2018 Fun-Robo Simple Arduino Robot Controller (ENGR3390 Tutorial 4)
* Description: This structure template contains a SENSE-THINK-ACT data flow to
* allow a Robot to perform a sequence of meta-behaviors in soft-real-time based on direct
* text commands from a human operator.
* Robot Name?: ***add name here** Example; TutorialBot 1
* What does code do?: ****give a short description of what code does*** Example; poll operator,
* carry out operator text input, loop indefinitely