Skip to content

Instantly share code, notes, and snippets.

View blindman2k's full-sized avatar

Aron Steg blindman2k

  • Launch Systems Pty Ltd
  • Melbourne, Australia
View GitHub Profile
@blindman2k
blindman2k / generate_token.html
Last active August 29, 2015 14:02
These files are to support the blog post on Firebase security at https://community.electricimp.com/blog/firebase-security/
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Create or test Firebase tokens - by katowulf</title>
<script type="text/javascript" src="https:////cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript" src="https://static.firebase.com/v0/firebase.js"></script>
<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase-token-generator.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Base64/0.2.0/base64.min.js"></script>
@blindman2k
blindman2k / DA14580.agent.nut
Created July 1, 2014 22:42
Dialog DA14580 programmer. Upload a HEX file and it programs the DA14580.
server.log("Agent started, URL is " + http.agenturl());
//------------------------------------------------------------------------------------------------------------------------------
program <- null;
html <- @"<HTML>
<BODY>
<form method='POST' enctype='multipart/form-data'>
@blindman2k
blindman2k / MAX3421E.device.nut
Created July 2, 2014 20:31
First attempt at a driver for the MAX3421E USB Host
// -----------------------------------------------------------------------------
// USB Host Shield pinouts
//
// 1- CS (not sure if it's active high/low)
// 2- MISO
// 5- SCLK
// 7- MOSI
// 8- RESET (also not sure about active high/low)
// 9- Interrupt (not sure if this is useful for anything)
@blindman2k
blindman2k / LEDDisplay.agent.nut
Last active August 29, 2015 14:03
This is some old code we used to light up the 16x16 LED display. The image loading no longer works because we lost the PHP code which used ImageMagick to convert the JPEGs and animated GIFS into bitstreams. But the rest works fine.
// ------------------------------------------------------------------------
// Takes a string, renders it and sends it to the device for display
text <- null;
function displayText(_text) {
device.send("text", _text);
text = _text;
}
// ------------------------------------------------------------------------
@blindman2k
blindman2k / example.agent.nut
Last active August 29, 2015 14:04
This HTTPRetry class automatically retries http requests when the agent backend throttles the request with a 429 error. Use it as you would the http object.
HTTPRetry.get("http://icanhazip.com").sendasync(function(res) {
if (res.statuscode == 200) {
server.log(res.body);
} else {
server.log("Error: " + res.statuscode);
}
});
@blindman2k
blindman2k / httpplus.agent.nut
Created July 23, 2014 00:07
HTTPPlus is an optimised http object replacement. It adds retry and redirect support for Imp agents. It also automatically converts tables to JSON requests.
// -----------------------------------------------------------------------------
class HTTPPlus {
_http = null;
// .........................................................................
// Keep a copy of the original http object for internal use
constructor() {
_http = http;
}
@blindman2k
blindman2k / number_format.nut
Created August 22, 2014 18:13
A handy utility function for formatting a number (integer or float) with a specified number of decimal places and commas at the thousand places.
function number_format(num, decimals=null, separator=",") {
// Fix the decimals
if (decimals == null) {
if (typeof num == "string") decimals = 0;
else if (typeof num == "integer") decimals = 0;
else if (typeof num == "float") decimals = 2;
else return num;
}
// Check we have a number or convert to one if required
if (typeof num == "string") {
@blindman2k
blindman2k / tempbug.agent.nut
Created October 8, 2014 00:29
Simple Nora temp bug which records and displays temperature and humidity graphs.
// -----------------------------------------------------------------------------
const html = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
@blindman2k
blindman2k / meeting_minder.agent.nut
Last active August 29, 2015 14:10
Meeting minder using the latest Google Calendar API for PHP.
//------------------------------------------------------------------------------------------------
const CALENDAR_URL = "http://devious-dorris.gopagoda.com/meeting_minder";
const REFRESH_TIME = 60; // Once a minute
SESSION_TOKEN <- "token" in server.load() ? server.load().token : "";
// server.log(SESSION_TOKEN);
function check_calendar(reschedule = true) {
local headers = {};
headers["X-GCal-Session-Token"] <- SESSION_TOKEN;
/* Environmental Sensor Tail Firmware
* Ambient Light Sensor: APDS-9007-020 (http://www.avagotech.com/docs/AV02-0512EN)
* Air Pressure Sensor: LPS25HTR (http://www.st.com/web/en/resource/technical/document/datasheet/DM00066332.pdf)
* Humidity/Temp Sensor: SI7020-A10-GMR (http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7020.pdf)
*/
const LPS25H_ADDR = 0xB8; // 8-bit I2C Student Address for LPS25HTR
const SI7020_ADDR = 0x80; // 8-bit I2C Student Address for SI7020
const ALS_RLOAD = 47000.0; // load resistor value on ALS
const READING_INTERVAL = 3; // seconds between readings