Skip to content

Instantly share code, notes, and snippets.

View jscrane's full-sized avatar

Stephen Crane jscrane

View GitHub Profile
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")
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):
import copy
import numpy as np
# DO NOT MODIFY THIS FUNCTION
def convert_tree_as_set_to_adjacencies(tree):
"""
This snippet of code converts between two representations we use for
edges (namely, with Chow-Liu it suffices to just store edges as a set of
pairs (i, j) with i < j), whereas when we deal with learning tree
#!/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
wemo_get()
{
local host=$1
cat << EOF |
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"/>
@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:a613f88bf988eab4bd18
Last active October 11, 2015 12:45
mspdebug trace
msp430fr5739$ /usr/local/energia/hardware/tools/msp430/bin/msp430-nm Blink.elf > Blink.out
msp430fr5739$ mspdebug -q rf2500
Trying to open interface 1 on 056
rf2500: warning: can't detach kernel driver: No data available
Device: MSP430FR5739
fet: FET returned NAK
warning: device does not support power profiling
(mspdebug) sym import Blink.out
(mspdebug) setbreak setup
Set breakpoint 0
@jscrane
jscrane / tinytest.ino
Last active August 29, 2015 14:20
Interrupted example for ATtiny85
#include <Interrupted.h>
#define LED 0
#define TIMER 1
#define BUTTON 2
Watchdog timer(TIMER, 1);
External button(BUTTON, LOW);
PinChangeGroup portb;
PinChange led(LED, portb);
@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: