This file contains hidden or 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 path = require('path'), | |
fs = require('fs'); | |
var outputFilePath = path.join(__dirname, 'write.txt'); | |
var writeStream = fs.createWriteStream(outputFilePath); | |
var inputFilePath = path.join(__dirname, 'test.txt'); | |
var readStream = fs.createReadStream(inputFilePath); | |
writeStream.on('pipe', function(){ |
This file contains hidden or 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 path = require('path'), | |
fs = require('fs'); | |
var outputFilePath = path.join(__dirname, 'write.txt'); | |
var writeStream = fs.createWriteStream(outputFilePath); | |
var inputFilePath = path.join(__dirname, 'test.txt'); | |
var readStream = fs.createReadStream(inputFilePath); | |
writeStream.on('error', function(err){ |
This file contains hidden or 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 path = require('path'), | |
fs = require('fs'); | |
var filepath = path.join(__dirname, 'write.txt'); | |
var writeStream = fs.createWriteStream(filepath); | |
writeStream.write('Hello World!'); | |
writeStream.end(); | |
writeStream.on('error', function(err){ |
This file contains hidden or 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 path = require('path'), | |
fs = require('fs'); | |
var filepath = path.join(__dirname, 'test.txt'); | |
var readStream = fs.createReadStream(filepath, {bufferSize:4}); | |
readStream.setEncoding('utf8'); | |
readStream.on('data', function(data){ | |
console.log(data); | |
}); |
This file contains hidden or 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 events = require('events'); | |
var util = require('util'); | |
function AsyncCB(cb){ | |
if(cb){ | |
process.nextTick(function(){ | |
cb(); | |
}); | |
} | |
} | |
util.inherits(AsyncCB, events.EventEmitter); |
This file contains hidden or 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 events = require('events'); | |
var util = require('util'); | |
function AsyncEmitter(){ | |
var self = this; | |
process.nextTick(function(){ | |
self.emit('bar'); | |
}); | |
} | |
util.inherits(AsyncEmitter, events.EventEmitter); | |
var foo = new AsyncEmitter(); |
This file contains hidden or 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
if(require.main === module){ | |
console.log(__filename); | |
} | |
if(!module.parent){ | |
console.log(__filename); | |
} |
This file contains hidden or 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 count = 0; | |
module.exports = { | |
say: function(name){ | |
count++; | |
console.log('Hello ' + name); | |
}, | |
getCount: function(){ | |
return count; | |
}, |
This file contains hidden or 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 http = require('http') | |
http.createServer(function(req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
}).listen(1337, '192.168.11.14'); | |
console.log('Server running at http://192.168.11.14:1337/'); |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
total = 500 | |
coins = [1, 5, 10, 50, 100, 500] | |
size = total/coins.min | |
ret = 1.upto(size).inject([]) do |r, n| | |
comb = coins.repeated_combination(n) | |
r + comb.select do |c| | |
c.inject(:+).eql?(total) |