Skip to content

Instantly share code, notes, and snippets.

View tanepiper's full-sized avatar

Tane Piper tanepiper

View GitHub Profile
@tanepiper
tanepiper / twitter_oauth_getter.js
Created September 11, 2010 16:14
A small command line nodejs script for doing Twitter OAuth.
#!/usr/bin/env node
var argv = require('optimist')
.usage('Usage: --key=[consumer key] -secret=[consumer secret]')
.demand(['key', 'secret'])
.argv
;
var OAuth = require('oauth').OAuth;
var Step = require('step');
YUI({ debug: DEBUG }).use('node', function(remotePage) {
var url = 'http://example.com/foo.xml';
remotePage.fetch(url, function() {
var userIdItems = remotePage.all('Users OnlineUsers OnlineUser UserID');
userIdItems.each(function(item) {
console.log(item.get('innerHTML');
// Get an attr
console.log(item.get('someattr');
exports.render_to_response = function(responseInst, data, code, headers) {
responseInst.send(data, headers, code);
responseInst.end();
}
var http = require('http');
var fs = require('fs');
var url = require('url');
var word = process.argv[2];
var google = http.createClient(80, 'ajax.googleapis.com');
var request = google.request('GET', '/ajax/services/search/images?q=' + word + '&v=1.0&safe=off', {'host': 'ajax.googleapis.com'});
@tanepiper
tanepiper / database.js
Created December 4, 2010 13:37
Create this in database.js and then in project to var database = require('database'); You can then use database. namespace to access database methods
/**
* database.js
* The core database setup file for the project
*/
/**
* The couchdb module instance
*/
var cradle = require('cradle');
@tanepiper
tanepiper / search-results.js
Created January 21, 2011 23:55
Call the file using node with a keyword to search. `node search-results.js "nodejs rocks"`
var start = new Date().getTime();
var jsdom = require('jsdom').jsdom;
var request = require('request');
var argv = require('optimist')
.usage('numresults <word>')
.check(function(argv) { if (argv._.length == 0) throw '' })
.argv;
var url = 'http://www.google.com/search?hl=en&q=' + encodeURIComponent(argv._[0]);
console.log(url);
request({uri: url}, function(error, response, body) {
var frames = 0, last = 0;
setInterval(function () {
if (last) {
var fps = frames / (Date.now() - last) * 1000;
console.log('fps: ' + fps);
}
last = Date.now();
frames = 0;
}, 1000);
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'
require.paths.unshift('#{__dirname}')
express = require 'express'
app = express.createServer()
app.configure( () ->
app.set 'views', '#{__dirname}/views'
app.use express.logger()
app.use express.bodyDecoder()
module.exports = (settings) ->
cradle = require('cradle')
return new(cradle.Connection)(settings.database.host, settings.database.port, settings.database.options)