Skip to content

Instantly share code, notes, and snippets.

View krhoyt's full-sized avatar

Kevin Hoyt krhoyt

View GitHub Profile
@krhoyt
krhoyt / switch.css
Last active November 10, 2017 19:40
This is an example of how to pass data from a web page, through PHP, to an Electric Imp. The example is a light switch that turns an LED on and off based on the value passed.
/*
* Background gradient generated using ColorZilla
* http://www.colorzilla.com/gradient-editor
*/
body {
background: #dddedd;
background: -moz-linear-gradient( -45deg, #dddedd 0%, #d5d6d6 100% );
background: -webkit-linear-gradient( -45deg, #dddedd 0%, #d5d6d6 100% );
background: -o-linear-gradient( -45deg, #dddedd 0%, #d5d6d6 100% );
background: -ms-linear-gradient( -45deg, #dddedd 0%, #d5d6d6 100% );
@krhoyt
krhoyt / getage.js
Last active December 15, 2015 20:09
Returns the number years, months, days and minutes that have elapsed since a given date. Designed for displaying my daughters age on her web site.
var MILLIS_DAY = 24 * 60 * 60 * 1000;
var MILLIS_HOUR = 60 * 60 * 1000;
var MILLIS_MINUTE = 60 * 1000;
var MILLIS_MONTH = 30 * 24 * 60 * 60 * 1000;
var MILLIS_YEAR = 31557600000;
function getAge( birthday )
{
var days = null;
var difference = null;
@krhoyt
krhoyt / quickbase.php
Created April 5, 2013 03:30
General access to QuickBase database through the XML-RPC API using PHP.
<?php
$username = "_USER_NAME_";
$password = "_PASSWORD_";
$token = "_TOKEN_";
$dbid = "_DATABASE_ID_";
$access = authenticate( $username, $password );
$survey = questions( $dbid, $token, $access["ticket"] );
@krhoyt
krhoyt / send-twilio.m
Last active December 27, 2015 16:59
Send a text message using the Twilio service.
- ( void ) sendTwilioTextMessage : ( NSString * ) toNumber withBody : ( NSString * ) body
{
NSArray * items;
NSData * post;
NSError * error;
NSHTTPURLResponse * response;
NSMutableURLRequest * request;
NSString * contents;
NSXMLDocument * doc;
@krhoyt
krhoyt / create-write-xml.m
Last active December 27, 2015 16:59
Create an XML document and write it to disk.
- ( void ) createAndWriteXMLDocument : ( NSString * ) fileName
{
NSArray * directories;
NSData * output;
NSFileManager * manager;
NSMutableString * path;
NSXMLDocument * doc;
NSXMLElement * root;
NSXMLNode * first;
NSXMLNode * last;
@krhoyt
krhoyt / load-parse-xml.m
Last active December 27, 2015 16:59
Load an XML file, parse the contents, and find a specific node.
- ( void ) loadAndParseXMLFile : ( NSString * ) url
{
NSArray * items;
NSArray * query;
NSError * error;
NSXMLDocument * doc;
NSXMLNode * item;
// XPath for the win!
doc = [[NSXMLDocument alloc] initWithContentsOfURL : [NSURL URLWithString : url] options : ( NSXMLNodePreserveWhitespace | NSXMLNodePreserveCDATA ) error : &error];
@krhoyt
krhoyt / http-post.m
Last active December 27, 2015 16:59
Make an HTTP POST and read the response content into a string for further processing.
- ( NSString * ) loadFileHTTPFormPost : ( NSString * ) url withFormData : ( NSDictionary * ) parameters
{
NSData * post;
NSError * error;
NSHTTPURLResponse * response;
NSMutableString * location;
NSMutableURLRequest * request;
NSString * contents;
NSString * form;
@krhoyt
krhoyt / http-query-string.m
Last active December 27, 2015 16:59
Send an HTTP GET request with query string values.
- ( NSString * ) encodeDictionary : ( NSDictionary * ) parameters
{
NSMutableString * query;
query = [[NSMutableString alloc] init];
[parameters enumerateKeysAndObjectsUsingBlock : ^( id key, id value, BOOL *stop ) {
[query appendFormat : @"%@=%@&", key, value];
}];
@krhoyt
krhoyt / http-get.m
Created November 7, 2013 18:32
Plain HTTP GET request.
- ( NSString * ) loadFileHTTPGet : ( NSString * ) url
{
NSArray * crayola;
NSArray * parts;
NSData * get;
NSError * error;
NSHTTPURLResponse * response;
NSMutableURLRequest * request;
NSString * contents;
@krhoyt
krhoyt / parse-json.m
Created November 7, 2013 18:33
Parse JSON content from a file.
- ( NSArray * ) parseJSONContent : ( NSString * ) fileName
{
NSArray * colors;
NSArray * directories;
NSData * buffer;
NSError * error;
NSFileHandle * handle;
NSFileManager * manager;
NSMutableString * path;
NSString * blue;