Skip to content

Instantly share code, notes, and snippets.

@seth10
seth10 / other_iteration_options.py
Created October 10, 2016 14:17
A few ways to iterate over pairs of coordinates for drawing a polyline in mindsensorsUI.py
for i in range(len(endpoints)/2):
actendpts.append(self.screenXFromImageCoords(endpoints[i*2],endpoints[i*2+1])) # actual x-coordinate
actendpts.append(self.screenYFromImageCoords(endpoints[i*2],endpoints[i*2+1])) # actual y-coordinate
for i in [x * 2 for x in range(len(endpoints)/2)]: # iterate over every other integer [0, 2, 4, ...]
actendpts.append(self.screenXFromImageCoords(endpoints[i],endpoints[i+1])) # actual x-coordinate
actendpts.append(self.screenYFromImageCoords(endpoints[i],endpoints[i+1])) # actual y-coordinate
for (x,y) in [(endpoints[i*2],endpoints[i*2+1]) for i in range(len(endpoints)/2)]: # iterate over each pair of integers
actendpts.append(self.screenXFromImageCoords(x,y)) # actual x-coordinate
@seth10
seth10 / varargsTest.py
Created October 10, 2016 14:21
Experimenting using a variable number of arguments in Python for drawing a polyline
def drawPolyLine(*args, **kwargs):
width = kwargs.pop('width', 0)
fill = kwargs.pop('fill', (255,255,255))
display = kwargs.pop('display', True)
print "width: %s\nfill: %s\ndisplay: %s" % (width, fill, display)
for arg in args:
print arg
@seth10
seth10 / wait4Acknowledgement.ino
Created October 11, 2016 19:38
Various approaches to waiting for the user to be ready before starting an EVShield test or example
evshield.waitForButtonPress(BTN_GO);
evshield.waitForButtonPress(BTN_GO, 1); // "breathing" led pattern: http://www.mindsensors.com/reference/EVShield/html/class_e_v_shield.html#af6551565c91c30c4dcbf3816f45832ed
while (!evshield.getButtonState(BTN_GO)) {
if (millis() % 1000 < 3) {
Serial.println("Press GO button to continue");
}
}
str = "One Two\nThree Four";
str.split('\n').map(function(l){return l.split(' ');});
// https://cloud.githubusercontent.com/assets/5026621/19372551/0d04c452-918b-11e6-8245-70bf616d3458.png
//or
str.split('\n').map(String.prototype.split.bind(' '));
@seth10
seth10 / Faction.java
Created October 14, 2016 23:38
Creates a basic fraction with a numerator and denominator field.
/*
Fraction.java - Version 1.01 - 6/7/2013
_____ _ _ _____ _
/ ___| | | | | |_ _| | |
\ `--. ___| |_| |__ | | ___ _ __ ___ _ __ ___ | |__ __ _ _ _ _ __ ___
`--. \/ _ \ __| '_ \ | |/ _ \ '_ \ / _ \ '_ ` _ \| '_ \ / _` | | | | '_ ` _ \
/\__/ / __/ |_| | | | | | __/ | | | __/ | | | | | |_) | (_| | |_| | | | | | |
\____/ \___|\__|_| |_| \_/\___|_| |_|\___|_| |_| |_|_.__/ \__,_|\__,_|_| |_| |_|
Creates a basic fraction with a numerator and denominator field.
@seth10
seth10 / GuassianElimination3.java
Created October 14, 2016 23:39
Guassian Elimination written in Java class, recovered from 2013
/*
GuassianElimination2.java - Version 1.01 - 5/16/2013
_____ _ _ _____ _
/ ___| | | | | |_ _| | |
\ `--. ___| |_| |__ | | ___ _ __ ___ _ __ ___ | |__ __ _ _ _ _ __ ___
`--. \/ _ \ __| '_ \ | |/ _ \ '_ \ / _ \ '_ ` _ \| '_ \ / _` | | | | '_ ` _ \
/\__/ / __/ |_| | | | | | __/ | | | __/ | | | | | |_) | (_| | |_| | | | | | |
\____/ \___|\__|_| |_| \_/\___|_| |_|\___|_| |_| |_|_.__/ \__,_|\__,_|_| |_| |_|
Description.
<html>
<title>CSS3 Animations Examples</title>
<head>
<style>
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes fadeInUp {
@seth10
seth10 / alexa_lambda.js
Last active November 26, 2016 13:53
The most simple AWS Lambda function for handling an Alexa request with the new Alexa Node.js SDK
'use strict';
var Alexa = require('alexa-sdk');
var APP_ID = 'amzn1.ask.skill.5f3759df-5f37-59df-5f3759df5f37';
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
@seth10
seth10 / alexa_lambda_2.js
Created November 26, 2016 13:51
It really should be this simple, but the lambda function returns before the request callback is executed
'use strict';
var Alexa = require('alexa-sdk');
var APP_ID = 'amzn1.ask.skill.5f3759df-5f37-59df-5f3759df5f37';
var request = require('request');
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
# you have
x1 = 3309
y1 = 2406
x2 = 3386
y2 = 506
x3 = 347
y3 = 426
x4 = 311
y4 = 2199
# and must assign the following to s.ts_cal: {'x1':3309, 'y1':2406, 'x2':3386, 'y2':506, 'x3':347, 'y3':426, 'x4':311, 'y4':2199}