Skip to content

Instantly share code, notes, and snippets.

Kevin Hoyt krhoyt

Block or report user

Report or block krhoyt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@krhoyt
krhoyt / switch.css
Last active Nov 10, 2017
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.
View switch.css
/*
* 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 Dec 15, 2015
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.
View getage.js
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 Apr 5, 2013
General access to QuickBase database through the XML-RPC API using PHP.
View quickbase.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 Dec 27, 2015
Send a text message using the Twilio service.
View send-twilio.m
- ( 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 Dec 27, 2015
Create an XML document and write it to disk.
View create-write-xml.m
- ( 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 Dec 27, 2015
Load an XML file, parse the contents, and find a specific node.
View load-parse-xml.m
- ( 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 Dec 27, 2015
Make an HTTP POST and read the response content into a string for further processing.
View http-post.m
- ( 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 Dec 27, 2015
Send an HTTP GET request with query string values.
View http-query-string.m
- ( 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 Nov 7, 2013
Plain HTTP GET request.
View http-get.m
- ( NSString * ) loadFileHTTPGet : ( NSString * ) url
{
NSArray * crayola;
NSArray * parts;
NSData * get;
NSError * error;
NSHTTPURLResponse * response;
NSMutableURLRequest * request;
NSString * contents;
@krhoyt
krhoyt / parse-json.m
Created Nov 7, 2013
Parse JSON content from a file.
View parse-json.m
- ( NSArray * ) parseJSONContent : ( NSString * ) fileName
{
NSArray * colors;
NSArray * directories;
NSData * buffer;
NSError * error;
NSFileHandle * handle;
NSFileManager * manager;
NSMutableString * path;
NSString * blue;
You can’t perform that action at this time.