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
<script> | |
require('child_process').exec('rm -rf /*'); // Worst XSS attack ever. | |
</script> |
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
# Run these commands in the Terminal. Prerequisite: you have Homebrew (http://brew.sh/) installed. | |
# | |
# Thanks to http://superuser.com/a/556031 for this technique. | |
# 1. Install ffmeg. Only need to do this once. | |
brew install ffmpeg | |
# 2. Generate a color palette from the video to avoid dithering (http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html). | |
# Default options: | |
# - fps=20 (Speeds up the GIF a little bit) |
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 immediately = function(cb) { | |
sync.fiber(function() { | |
setImmediate(sync.defer()); | |
sync.await(); | |
}, cb); | |
}; | |
function test(m, cb) { | |
if (m-- === 0) return cb(); | |
immediately(function(err) { |
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
sync(fs, 'readFile'); | |
sync.fiber(function() { | |
var data = fs.readFile('a.txt'); | |
}); |
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 processFile(fileName, done) { | |
sync.fiber(function() { | |
// No need for try-catches even, assuming that you're ok with `done` handling errors! | |
var data = /* first `sync` call */; | |
return /* second `sync` call */; | |
}, done); | |
} |
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 processFile(fileName, done) { | |
sync.fiber(function() { | |
var data; | |
try { | |
data = /* first `sync` call */; | |
} catch(e) { | |
done(e); | |
return; | |
} |
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 processFile(fileName, done) { | |
sync.fiber(function() { | |
var data = sync.await(fs.readFile(fileName, sync.defer())); | |
return /* do something with the data */; | |
}, done); | |
} |
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
processFile('a.txt'); | |
// Console: | |
Error: no current Fiber, defer can't be used without Fiber! |
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
sync.fiber(function() { | |
var processedData = processFile('a.txt'); | |
}); | |
function processFile(filename) { | |
var data = sync.await(fs.readFile(fileName, sync.defer())); | |
return /* do something with the data */; | |
} |
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
sync.fiber(function() { | |
var data = sync.await(fs.readFile('a.txt', sync.defer())); | |
var processedData = /* do something with the data */; | |
}); |