This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node-jquery - port of jquery 1.4.2 (http://jquery.com/)to node.js by alex bosworth (http://alexbosworth.net/) | |
function now() { | |
return (new Date).getTime(); | |
} | |
var window = {}, | |
jsc = now(), | |
rscript = /<script(.|\s)*?\/script>/gi, | |
rselectTextarea = /select|textarea/i, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Alex Bosworth | |
* | |
* A straightforward S3 library | |
* | |
* USE: var s3 = new S3(AWS_KEY, AWS_SECRET, {defaultBucket : MY_BUCKET}); | |
* s3.put(KEY, DATA); | |
* s3.get(KEY).on('success', function(data) { console.log(data); }); | |
* (more operations: buckets, info, list) | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for node-jquery.js (http://gist.github.com/599831) | |
// add this to a script to show how long it took to complete | |
process.on('exit', $.proxy(function () { | |
var sec = Math.round((new Date().getTime() - this.start.getTime()) / 1000); | |
console.log('completed', 'in ' + sec + ' seconds'); | |
}, {start:new Date()})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Alex Bosworth | |
* | |
* A straightforward S3 library | |
* | |
* USE: var s3 = new S3(AWS_KEY, AWS_SECRET, {defaultBucket : MY_BUCKET}); | |
* s3.put(KEY, {data:{},headers:{}}, [bucket]); | |
* s3.get(KEY, [bucket]).on('success', function(data) { console.log(data); }); | |
* (more operations: buckets, info, list) | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SCRIPT IN PROGRESS! BEWARE SUPER HACKY/UGLY CODE BELOW | |
// takes an associative array of args "a[b][c]" = d into a : { b : { c : d } } | |
// use: var getArgs = parseGetArgs(url.parse(request.url, true).query); | |
function parseGetArgs(args) { | |
if (!args) return null; | |
var result = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** Steps ** | |
Problem: | |
Map asynchronous callbacks onto a multi-step process. | |
Centralize flow logic | |
object { | |
steps : [function, function, function] | |
advance : function() { this.shift(function)(); } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function echo(string) { console.log(string); } | |
process.on('uncaughtException', function (err) { | |
echo(err.stack); | |
echo('uncaught Exception: ' + err); | |
}); | |
var KEYS = require('keychain'), | |
$ = require('node-jquery'), | |
S3 = require('amazon-s3').S3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sdb.prototype.getQueryString = function(query) { | |
if (!query.domain) throw new Error('no domain specified'); | |
if (!query.fields || !query.fields.length) query.fields = '*'; | |
var str = query.fields.join() + ' from ' + query.domain; | |
if (query.selectors && query.selectors.length) | |
str+= ' where ' + query.selectors.join(' intersection '); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function now() { | |
return (new Date).getTime(); | |
} | |
var window = {}, | |
jsc = now(), | |
rscript = /<script(.|\s)*?\/script>/gi, | |
rselectTextarea = /select|textarea/i, | |
rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i, | |
jsre = /=\?(&|$)/, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deferreds are useful for chaining: doSomething().success(doSomethingElse).failure(stopStuff); | |
function Deferred() { | |
this._successCbk = function() {}, | |
this._failureCbk = function() {}; | |
return this; | |
} | |
Deferred.prototype.success = function(cbk) { | |
this._successCbk = cbk; |
OlderNewer