Skip to content

Instantly share code, notes, and snippets.

View jscrane's full-sized avatar

Stephen Crane jscrane

View GitHub Profile
@jscrane
jscrane / spwm.ino
Created July 5, 2012 08:05
Software PWM for Arduino/ATtiny
void spwm(int freq, int pin, int spd) {
digitalWrite(pin, HIGH);
delayMicroseconds(spd * freq);
digitalWrite(pin, LOW);
delayMicroseconds(spd * (255 - freq));
}
int delay = 15;
void loop() {
@jscrane
jscrane / .gitignore
Last active February 20, 2019 15:22
TinySensor sketch
.lib
*.cpp.o
tinysensor.ino.bin
tinysensor.ino.elf
tinysensor.eep
@jscrane
jscrane / .gitignore
Last active February 20, 2019 07:46
Sketch to test a TinySensor and commission it by setting its node-id in EEPROM
.lib
*.cpp.o
*.ino.bin
*.ino.elf
*.eep
.*.swp
date,time,sys,dia,pulse
2019-02-09,15:17:44,129,86,69
2019-02-09,08:48:58,120,84,63
2019-02-08,19:29:04,116,78,71
bp <- read.csv(file="/tmp/x.csv", header=TRUE, sep=",")
bp$date = as.Date(bp$date)
n = nrow(bp)
bq <- bp[order(bp$date, bp$time),]
matplot(bq, type="p", xaxt="n")
@jscrane
jscrane / Philosophers.ino
Last active November 13, 2018 02:27
Dining Philosophers for the Arduino Uno
#define MAX 5
Semaphore forks[MAX];
byte ids = 1;
byte leds[] = { 5, 6, 7, 8, 9 };
void eating(byte id) {
digitalWrite(leds[id], HIGH);
Tasks::delay(1 + random(MAX * 100));
digitalWrite(leds[id], LOW);
}
@jscrane
jscrane / gist:a74c447729a0a3677593
Created March 10, 2015 12:42
Finding Similar Sentences
#!/usr/bin/env python
import sys
import string
# while lines are hashed as-is into a map where values are
# sets of indices.
def hash_whole(hashes, idx, s):
h = hash(s)
if not h in hashes:
#!/bin/bash
PATH=/usr/local/bin:$PATH
WEMO=wemo
HOST=iot
CLIENT=wemo_mqtt
STAT=stat/wemo/power
CMND=cmnd/wemo/power
. wemo_functions.sh
@jscrane
jscrane / wemo.sh
Last active December 3, 2016 15:19
bash wemo control script
#!/bin/bash
PATH=/usr/local/bin:$PATH
WEMO=wemo
. wemo_functions.sh
case $# in
0)
wemo_get $WEMO
import numpy as np
# Predicts the label based on the sum of the observations with tolerance around 0
#
# ('Training accuracy for prediction +1:', 0.64809384164222872)
# ('Training accuracy for prediction -1:', 0.37745098039215685)
# ('Training accuracy for prediction 0:', 0.3524945770065076)
#
# Grader Score: 44.29%
import sys
import os.path
import numpy as np
import collections
import util
USAGE = "%s <test data folder> <spam folder> <ham folder>"
def get_counts(file_list):