Skip to content

Instantly share code, notes, and snippets.

View tcr's full-sized avatar
🚮
bad command or file name

Tim Ryan tcr

🚮
bad command or file name
View GitHub Profile
@tcr
tcr / gist:5166129
Last active December 14, 2015 23:29
/** A low-level look at an HTTP API */
// Make the GET request to the Facebook API.
Facebook.get("me/notifications?limit=1", access_token);
Facebook.match(onNotification, "data", JSON_ARRAY, "title"); // "data" key, find ARRAY, identify each "title" key
Facebook.match(onError, "error");
Facebook.request();
// Make the GET request to the Facebook API.
Facebook.post("me/feed", access_token);
/*
* Modified from WiFlyHQ Example httpclient.ino
*
* This sketch implements a simple Web client that connects to a
* web server, sends a GET, and then sends the result to the
* Serial monitor.
*
* This sketch is released to the public domain.
*
*/
@tcr
tcr / gist:5108489
Created March 7, 2013 14:42
Testing Twitter official API keys
// npm install rem read
var rem = require('rem')
, fs = require('fs')
, read = require('read');
var tw = rem.connect('twitter.com', '1.1')
, oauth = rem.oauth(tw);
// Add whichever API keys you want to test here.
// Including the iPhone/Android apps, these keys are configured as "desktop"
@tcr
tcr / gist:5031938
Created February 25, 2013 18:12
Script to apply to the Startup Park with Node.js
var rem = require('rem');
var api = rem.createClient({
base: 'http://www.startuppack.org/v1/',
uploadFormat: 'form'
});
api('users').post({
token: ..., // your token
email: "id@timryan.org",
@tcr
tcr / graphbutton.md
Last active December 12, 2015 09:29
Walkthrough: Connecting a circuit to Facebook's Open Graph.

Walkthrough: A circuit that posts to the Open Graph

What you’ll learn: How to create a circuit that posts an action to your profile on the Open Graph.

What you'll need:

  • An Electric Imp
  • An Electric Imp breakout board, or an Arduino + an Electric Imp Shield
  • A switch or some wire

Setting up an Arduino + Electric Imp Shield

@tcr
tcr / gist:4752180
Last active December 12, 2015 09:29
Source code for the Electric Imp GraphButton example.
// GraphButton source code
// Set output port for planner.
local output = OutputPort("trigger");
// Callback when the button is pressed.
function pin7changed() {
local buttonState = hardware.pin7.read();
// If buttonState is 0, the button is pushed.
@tcr
tcr / summary.md
Last active December 10, 2015 23:18
How can you detect browser vs. Node.js vs CommonJS?
var isNode = typeof process != 'undefined' && process.versions && process.versions.node;

var isBrowser = typeof window != 'undefined';  

var isModule = typeof module != 'undefined' && module.exports;
@tcr
tcr / summary.md
Created January 4, 2013 05:06
How do you escape HTML entities, JavaScript unicode values, or CSS content values, and convert between them?

This converter converts between entities.

@tcr
tcr / gist:4446743
Last active December 10, 2015 14:19
List a user's Github repos using Rem.
// npm install rem read
var rem = require('rem')
, read = require('read');
var github = rem.connect('github.com', 3.0)
read({ prompt: 'Username: '}, function (err, username) {
github('users', username, 'repos').get(function (err, repos) {
console.log(repos);
});
@tcr
tcr / prom.js
Last active December 10, 2015 10:39
Logical, simple promises in JavaScript, cause I can never remember this Q business
// Calls functions once a promise has been delivered.
// var p = promise();
// Queue functions: p(yourCallback)
// Deliver the promise: promise.deliver([args...]).
// Once the promise has been delivered, p(yourCallback) immediately calls the callback.
function promise () {
var queue = [], args = null;
var promise = function (fn) {
if (promise.delivered) {