Skip to content

Instantly share code, notes, and snippets.

View madpilot's full-sized avatar

Myles Eftos madpilot

View GitHub Profile
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "........";
const char* password = "........";
ESP8266WebServer server(80);
blueprint:
name: Amber Light
description: Change the colour of a lamp based on the current Amber price
domain: automation
input:
amber_price_sensor:
name: Amber Price Sensor
description: The Amber price sensor you wish to track. If in doubt, use General Price.
selector:
entity:
@madpilot
madpilot / bitbang.c
Created January 16, 2017 21:42
Bit-bang me some binary
/* hello-ftdi.c: flash LED connected between CTS and GND.
This example uses the libftdi API.
Minimal error checking; written for brevity, not durability. */
#include <stdio.h>
#include <ftdi.h>
#include <time.h>
#define CTS 0x08 /* CTS (brown wire on FTDI cable) */
@madpilot
madpilot / scale.rb
Created January 16, 2017 21:28
Scale the pulse width to 1 from 1.04
#!/usr/bin/env ruby -w
require 'csv'
file = ARGV[0]
out = file.split('.').join('-normalized.')
unless file
puts "Usage: normalize [filename]"
exit(1)
end
@madpilot
madpilot / normalize.rb
Last active January 16, 2017 21:27
Normalize the LabNation export for my air conditioner, so each pulse is exactly 1.04
#!/usr/bin/env ruby -w
require 'csv'
file = ARGV[0]
out = file.split('.').join('-normalized.')
unless file
puts "Usage: normalize [filename]"
exit(1)
end
@madpilot
madpilot / compress.rb
Created January 16, 2017 21:23
Takes a LabNation export, and finds transitions. The file can be loaded in D3, for visualization
#!/usr/bin/env ruby -w
require 'csv'
file = ARGV[0]
out = file.split('.').join('-compressed.')
unless file
puts "Usage: compress [filename]"
exit(-1)
end
@madpilot
madpilot / svg-check
Created November 27, 2013 01:15
SVG check (Stolen from Modernizr
var svg = (!!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect);
The Problem: We have a WCF JSON API, that we need to make accessible from third-party sites (on IE7+), so JSON-P looks like a good solution.
Issue is, (what the .NET guy here has told me), each endpoint in the WCF router will need to be re-written (or added to) to handle GETs (We currently use GET, POST, and DELETE depending on the action). That sucks.
My idea: An IIS module (handler?) that intercepts JSON-P requests, and transforms the request to something the WCF router can handle, then pads the response. Basically transparent JSON-P padding around WCF.
Make sense? Does this exist already?
class Foo
def this_fails
puts self.bar
end
def this_works
puts bar
end
private
@madpilot
madpilot / haversize.rb
Created March 9, 2013 08:04
Ruby haversine - finds the distance between to long/lats. Can be used as a paramater for sort.
def haversine(x, y)
r = 6371
lat1 = x.latitude
lat2 = y.latitude
lon1 = x.longitude
lon2 = y.longitude
d_lat = (lat2 - lat1) * Math::PI / 180
d_lon = (lon2 - lon1) * Math::PI / 180