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 / facebook-status-stream.js
Created October 22, 2012 06:09
Create a stream out of any REST endpoint with REM's polling utility.
// npm install rem
var rem = require('rem');
// Create Facebook API, prompting for key/secret.
var facebook = rem.load('facebook', 1).prompt();
// Authenticate user via the console.
rem.console(facebook, function (err, user) {
// Poll new statuses at an interval of 1 second, finding the array
// at the 'data' key and checking the 'date' key for date comparison.
@tcr
tcr / debate-twitter-stream.js
Created October 17, 2012 04:24
See a streaming list of all tweets concerning the presidential debate.
// npm install rem read clarinet
var rem = require('rem');
var read = require('read');
var clarinet = require('clarinet');
// Create Twitter API, prompting for key/secret.
var tw = rem.load('twitter', 1.0).prompt();
// Authenticate user via the console.
rem.console(tw, function (err, user) {
@tcr
tcr / login.js
Created July 31, 2012 05:37
Persisting OAuth Bot for Google Docs using REM
// Run this first from the console to create an authentication object.
var rem = require('rem');
var fs = require('fs');
// Create Google Calendar API, prompting for key/secret.
var gdocs = rem.load('google-docs', 3.0, {format: 'xml'}).prompt();
// Authenticate user via the console.
rem.console(gdocs, function (err, user) {
@tcr
tcr / post-tweet.js
Created July 3, 2012 18:30
[rem-node] Post a tweet from the command line.
var rem = require('rem');
var read = require('read');
// Prompt and post a tweet from the command line.
rem.myConsole('twitter', 1.0, function(err, user) {
read({prompt: "Enter a status to tweet: "}, function (err, txt) {
user('statuses/update').post({status: txt}, function (err, json) {
console.log('Response:', err, json);
});
});
@tcr
tcr / tags.json
Created June 21, 2012 17:46
How do Node.js streams work?
["node.js","streams"]
@tcr
tcr / generator.coffee
Created June 17, 2012 08:53
Generators using IcedCoffeeScript
# Generators and "yield" in IcedCoffee
# See: https://developer.mozilla.org/en/JavaScript/Guide/Iterators_and_Generators
# Try it: http://maxtaco.github.com/coffee-script/
# We can mimick much of the Generator functionality of JavaScript 1.7
# using IcedCoffeeScript's Deferrals.
#
# We define a "generator" function that can be given a function and return a generator.
# To mimick yield, we use a passed argument, "cc", and await/defer on it. This holds on
# to the deferral callback until the next time the function is invoked.
@tcr
tcr / output.txt
Created April 30, 2012 08:09
Get a DOM element's unique API
<h4>API for video element</h1>
<pre id="asdf" rows="30" cols="30"></pre>
<script>
var asdf = document.getElementById('asdf');
var v = document.createElement('video');
var s = document.createElement('span');
for (var k in v) if (!(k in s)) asdf.innerText += k + (typeof v[k] == 'function' ? '()' : '') + '\n';
</script>
@tcr
tcr / tagr.coffee
Created April 15, 2012 17:23
Array-like HTML manipulation.
class EventEmitter
listeners: (type) ->
if @hasOwnProperty.call (if @_events? then @_events else @_events = {}), type then @_events[type] else @_events[type] = []
on: (args...) -> @addListener args...
once: (type, f) -> @on type, g = (args...) -> f.apply(this, args); @removeListener type, g
addListener: (type, f) ->
if (@listeners(type).push f) > @_maxListeners and @_maxListeners != 0
console?.warn "Possible EventEmitter memory leak detected. #{@_events[type].length} listeners added. Use emitter.setMaxListeners() to increase limit."
@emit "newListener", type, f
this
@tcr
tcr / summary.md
Created January 8, 2012 18:41
How do you prevent the play button from launching iTunes in OS X Lion?

It seems to require a script for the moment. It disables the launching capability when iTunes is closed, but preserves all other capabilities.

@tcr
tcr / summary.md
Created January 5, 2012 01:29
How can you make a CLI with Node.js?

Poll stdin, parse results.