Skip to content

Instantly share code, notes, and snippets.

View cojohn's full-sized avatar

Christopher John cojohn

View GitHub Profile
@cojohn
cojohn / custom-objects-in-arrays.js
Created February 17, 2012 18:40
Is there a better way to test for a custom Object in an array of custom Objects?
// `id` is a custom Object and `Actor.getTips()` is an array of `id`s
Actor.prototype.hasTipped = function(id) {
return new RegExp(id.toString())
.test(this.getTips().toString());
}
/*
* Specifically, these are MongoDB ObjectIDs from the node-mongodb-native repository.
* Actor.getTips().indexOf(id) does not work because `===` returns false on, say,
* Actor.getTips()[0] === id.
@cojohn
cojohn / basic-http-auth-node.js
Created February 8, 2012 18:53
Basic HTTP Authorization Header in Node.js
var key = <my key>,
secret = <my secret>,
https = require("https"),
https_options = {
"host": <host>,
"path": <path>,
"port": <port>,
"method": <method>,
"headers": {
"Authorization": "Basic " + new Buffer(key + ":" + secret, "utf8").toString("base64")