Skip to content

Instantly share code, notes, and snippets.

View streunerlein's full-sized avatar

Dominique Sandoz streunerlein

View GitHub Profile
@streunerlein
streunerlein / gist:3378008
Created August 17, 2012 11:05
Array.map() that works with undefined values in Array
Array.prototype.ownMap = function(fn) { var a = new Array(this.length); for (var i = 0; i < this.length; i++) a[i] = fn(this[i]); return a; }
// t = new Array(4)
// > [undefined × 4]
// t.ownMap(function(d) { return "Q"; })
// > ["Q", "Q", "Q", "Q"]
// t
// > [undefined × 4]
@streunerlein
streunerlein / gist:3332181
Created August 12, 2012 14:58
NPM Mirrors & Proxies

Definition

Mirrors: standalone servers with complete copy of npm registry

Proxies: proxy to the database (couchdb) of npm registry, if only the npm registry server fails but the db works

## HowTo See this gist: https://gist.github.com/3331671

Mirrors

(+) means server is self updating (pulls newest stuff from offical registry when back online again)

# use the npm mirror:
npm set registry http://ec2-46-137-149-160.eu-west-1.compute.amazonaws.com
# you can reset this later with npm set registry npm set registry https://registry.npmjs.org/
# then use it normally:
npm install express
function GetVendorPrefix(arrayOfPrefixes) {
var tmp = document.createElement("div");
var result = "";
for (var i = 0; i < arrayOfPrefixes.length; ++i) {
if (typeof tmp.style[arrayOfPrefixes[i]] != 'undefined'){
result = arrayOfPrefixes[i];
break;
@streunerlein
streunerlein / gist:2784839
Created May 24, 2012 23:20
How to pipe attachments from couchdb - without losing nice caching effects [nano]
var couchconfig = {
hostname: "localhost"
}
var nano = require("./nano/nano.js")("http://" + couchconfig.hostname + ":5984"),
db = nano.use("nano-test"),
express = require("express");
var app = express.createServer();