Setup:
$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
| /* | |
| * Copyright (c) 2010 Tobias Schneider | |
| * This script is freely distributable under the terms of the MIT license. | |
| */ | |
| (function(){ | |
| var UPC_SET = { | |
| "3211": '0', | |
| "2221": '1', | |
| "2122": '2', |
| // (c) copyright unscriptable.com / John Hann | |
| // License MIT | |
| // For more robust promises, see https://github.com/briancavalier/when.js. | |
| function Promise () { | |
| this._thens = []; | |
| } | |
| Promise.prototype = { |
| function transpose(a) | |
| { | |
| return a[0].map(function (_, c) { return a.map(function (r) { return r[c]; }); }); | |
| // or in more modern dialect | |
| // return a[0].map((_, c) => a.map(r => r[c])); | |
| } |
| var s = 'this-is-a-very-very-very-long-file-name.jpg'; | |
| console.log(truncate(s, 100)); //this-is-a-very-very-very-long-file-name.jpg | |
| console.log(truncate(s, 10)); //this-is-a-[...].jpg | |
| console.log(truncate(s, 4)); //this[...].jpg |
| var distances = { | |
| euclidean: function(v1, v2) { | |
| var total = 0; | |
| for (var i = 0; i < v1.length; i++) { | |
| total += Math.pow(v2[i] - v1[i], 2); | |
| } | |
| return Math.sqrt(total); | |
| }, | |
| manhattan: function(v1, v2) { | |
| var total = 0; |
| var mongoose = require('mongoose'); | |
| var db = mongoose.createConnection('127.0.0.1', 'test'); | |
| // Make schema | |
| var schema = mongoose.Schema({ name: String }); | |
| // Create subscribers collection | |
| var subscribers = []; | |
| // Hook `save` post method |
##Google Interview Questions: Product Marketing Manager
This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.
Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:
getTweetsFor("domenic", function (err, results) {
// the rest of your code goes here.| /*Transparent pattern placed over an image, like we see on the bootstrap homepage: http://twitter.github.com/bootstrap/index.html*/ | |
| div { | |
| width: 200px; | |
| height: 200px; | |
| display: block; | |
| position: relative; | |
| background: url(images/background-image.png); | |
| } |