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
$ npm install sqlite3 | |
npm http GET https://registry.npmjs.org/sqlite3 | |
npm http 304 https://registry.npmjs.org/sqlite3 | |
> sqlite3@2.1.5 install /Users/raulvieira/Development/img-crawler/node_modules/sqlite3 | |
> node-gyp rebuild | |
gyp http GET http://nodejs.org/dist/v0.8.18/node-v0.8.18.tar.gz | |
gyp http 200 http://nodejs.org/dist/v0.8.18/node-v0.8.18.tar.gz | |
CC(target) Release/obj.target/sqlite3/deps/sqlite3/sqlite3.o |
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
var stream = fs.createWriteStream(writeTo); | |
request(uri).on('response', function(response) { | |
if(response.statusCode === 200) { | |
this.pipe(stream); | |
} | |
}); |
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.prototype.repeat = function(count) { | |
return { | |
times: function(str) { | |
var i; | |
for (i = 0; i < count; i++) { | |
console.log(str); | |
} | |
} | |
} | |
}; |
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
// Exercise 2 - Closures | |
// Wrap the following code in a closure and export only the "countdown" function. | |
var exercise = (function() { | |
// Code | |
var index; | |
function log(){ | |
console.log(index); |
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.prototype.cached = function() { | |
var cache = {}, | |
that = this; | |
return function(arg) { | |
if(!(arg in cache)) { | |
cache[arg] = that(arg); | |
} | |
return cache[arg]; | |
}; |
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
var Person = function(name) { | |
this.name = name; | |
}; | |
Person.prototype.getName = function() { | |
return this.name; | |
}; | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); |