Skip to content

Instantly share code, notes, and snippets.

View pingswept's full-sized avatar

Brandon Stafford pingswept

  • Tufts University
  • Somerville, Massachusetts, USA
View GitHub Profile
@pingswept
pingswept / memoize-demo.py
Created March 4, 2021 17:00
Demo of how to memoize a function in Python
import functools
import timeit
import time
@functools.lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
/*
WiFi Web Server LED Blink
A simple web server that lets you blink an LED via the web.
This sketch will print the IP address of your WiFi module (once connected)
to the Serial monitor. From there, you can open that address in a web browser
https://us-school.pk12ls.com/school/fe1b3ad5-8762-4e0f-8e3d-56440bfbe441/D0680545/player.html
@pingswept
pingswept / drivestrength.ino
Created October 26, 2020 21:27
Fixing the drive strength mode on the Arduino MKR Wifi 1010
void setup() {
pinMode(4, OUTPUT);
setHighStrengthOutputPinMode(4);
}
void loop() {
digitalWrite(4, HIGH);
}
bool setHighStrengthOutputPinMode( uint32_t ulPin)
@pingswept
pingswept / ventilate.py
Last active July 1, 2018 00:08
Python script to turn a fan on and off based on SHT31 temperature and temperature from the internet
from Adafruit_IO import *
import json
import requests
import RPi.GPIO as GPIO
import smbus
import time
aio = Client('XXXXXXXXXXXXXXXXX_ADAFRUIT_API_KEY_GOES_HERE_XXXXXXXXXXXXXXXXX')
GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
@pingswept
pingswept / precision_voltage_shield.ino
Last active June 28, 2018 10:52
Code for reading voltages with the Precision Voltage Shield, an Arduino shield for reading very precisely. 8 channels; 14-bit, 16-bit, and 18-bit versions. More details at http://rascalmicro.com/blog/2013/03/21/bringing-an-analog-voltage-arduino-shield-to-life/
// Copyright 2014, Brandon Stafford, brandon@rascalmicro.com
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
@pingswept
pingswept / replify.py
Created August 8, 2017 14:54
Script for Chris to manipulate his G-code
infile = "infile.txt" # the file to open
copies = 3 # how many copies to make
marker = "STARTHERE\n"
with open(infile, 'r') as infile:
lines = infile.readlines()
#print(lines)
startline = lines.index(marker)
result = ''.join(lines + (lines[startline + 1:] * copies))
Brand Model Size Width Good/bad
New Balance Fresh Foam Gobi 14 EE Ill-fitting and stiff, but low arch is good. VL-6 last. Might be okay. Should try v2, will drop in July 2017.
New Balance Fresh Foam Hierro v2 14 4E Almost good but arch too high. Same PL-4 last as favorite MO69v1's. Disappointing.
New Balance Minimus 10v1 14 EE Almost good but arch too high. NL-1 last. Very comfy other than arch.
Montrail Fluid Flex FKT 14 -- WINNER! 8 pairs, 6 left. Update: not on Zappos any more. One color on columbia.com, May 2017.
Brooks Puregrit 4 14 -- Trevor recommended but haven't tried yet because of previous Brooks being too short in 14.
Topo MT-2 14 -- Kept. Might be serviceable.
Montrail Fluid Flex ST 14 -- WINNER! 3 pairs. Update: no longer available.
Nike Air Zoom Wildhorse 3 14 -- kept. Insole is a little stiff but could be a winner.
Montrail Fluid Flex II 14 ? Good. 1 pair. Blisters on long runs. Update: no longer available.
@pingswept
pingswept / scrape-sos-ri-gov.py
Last active January 28, 2016 19:27
Code to automatically retrieve representative and senatorial districts from ri.gov
import csv, re, requests
pattern = re.compile('<li>REPRESENTATIVE: (\d\d)</li>\n\t\t\t<li>SENATORIAL: (\d\d)</li>')
infile = csv.reader(open('addresses.csv', 'r'))
with open('output.csv', 'wb') as outfile:
for line in infile:
unique_id = line[0]
address = line[1]
@pingswept
pingswept / nginx.conf
Created December 20, 2013 22:44
Nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;