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 fs = require('fs'); | |
| var stream = require('stream'); | |
| var ts = new stream.Transform(); | |
| ts._transform = function(chunk, enc, cb) { | |
| // 'chunk' is the data from the readable source | |
| // | |
| // 'this.push(whatever)' or callback(err, whatever) writes | |
| // to target writeable |
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
| // Works (console.logs the headers) | |
| require('http').request('http://www.google.com') | |
| .on('response', function (response) { | |
| console.log(response.headers); | |
| }) | |
| .end(); | |
| // Doesn't work (hangs) | |
| require('http').request('http://www.google.com') | |
| .on('response', function (response) { |
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'); | |
| var bl = require('bl'); | |
| var server = http.createServer(function (req, res) { | |
| res.end('OK'); | |
| }).listen(3000); | |
| http.request('http://localhost:3000/') | |
| .on('response', function onResponse(response) { | |
| response.pipe(bl(function (err, 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
| // This will "hang" | |
| http.request('http://localhost:3000/') | |
| .on('response', function onResponse(response) { | |
| response.pipe(require('concat-stream')(function (data) { | |
| console.log(data); | |
| })); | |
| }) | |
| .end(); | |
| // Adding 'data' handler makes it terminate |
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
| // | |
| // This: (2 spaces, closures) | |
| // | |
| parallel([ | |
| function doSomeAsyncStuff (cb) { | |
| var fns = a.map(function (el) { | |
| return function (cb) { | |
| createElementOfSomeSort({ | |
| foo: el |
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
| function readOneLine(callback) { | |
| function readableListener () { | |
| var chunk = process.stdin.read(); | |
| if (!chunk) return; | |
| // Let's disconnect our event when we're ready to call back | |
| process.stdin.removeListener('readable', readableListener); | |
| // Attempt 1: |
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
| ~/$ for v in 2 3; do npm install graceful-fs@$v --loglevel=silent && node -e "require('graceful-fs'); require('fs').readdir('fake', function (err) { throw new Error(err); })"; done | |
| graceful-fs@2.0.3 node_modules/graceful-fs | |
| [eval]:1 | |
| graceful-fs'); require('fs').readdir('fake', function (err) { throw new Error( | |
| ^ | |
| Error: Error: ENOENT, readdir 'fake' | |
| at [eval]:1:78 | |
| at ReaddirReq.Req.done (/Users/aleksey/test-graceful-fs/node_modules/graceful-fs/graceful-fs.js:143:5) | |
| at ReaddirReq.done (/Users/aleksey/test-graceful-fs/node_modules/graceful-fs/graceful-fs.js:90:22) |
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
| process.stdin.on('readable', onReadable); | |
| console.log(process.stdin._events); | |
| process.stdout.write('Reading data:'); | |
| function onReadable() { | |
| var buf = process.stdin.read(); | |
| console.log(buf); | |
| if (!buf) return; |
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
| function listenForInput (callback) { | |
| process.stdout.write('Listening for input:'); | |
| function onReadable () { | |
| var chunk = process.stdin.read(); | |
| if (!chunk) return; | |
| console.log('Received: ', chunk.toString()); | |
| // Remove the readable listener |
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
| Option Compare Database | |
| Private Sub Form_Current() | |
| Dim MyTools(2) As String | |
| Dim MyButtons(2) As String | |
| Dim state As String | |
| Dim i As Integer | |
| Dim colors As New Dictionary(Of String, Integer) | |
| MyTools(1) = "Plasma-Therm Versaline" |