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
node helloworld.js | |
Server running at http://127.0.0.1:3000/ | |
# At this point in another terminal I use netcat to open a plain TCP connection, | |
# and then Ctrl-C to close the connection without having sent any data. | |
# node then blows up with: | |
Segmentation Fault | |
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 sys = require('sys'), | |
http = require('http'); | |
http.createServer(function (req, res) { | |
setTimeout(function () { | |
res.sendHeader(200, {'Content-Type': 'text/plain'}); | |
res.sendBody('Hello World'); | |
res.finish(); | |
}, 2000); | |
}).listen(3000); | |
sys.puts('Server running at http://127.0.0.1:3000/'); |
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
http.createServer(dispatchRequest).listen(port); | |
function dispatchRequest(req, res) | |
{ | |
res.sentinel = new Sentinel(function (e) { | |
// Like a catch() clause that catches callbacks too. | |
// Called if handleRequest throws, or if any of the callbacks | |
// registered by handleRequest throw, or if any of the |
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 node | |
var sys = require('sys'); | |
process.exceptionCatcher = function (e) { | |
sys.puts('Catcher 1 catches "' + e.message + '"'); | |
sys.puts('Catcher 1 returns'); | |
} |
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
Throwing from main | |
uncaughtException catches "thrown by main" | |
Timeout 1 throws | |
Catcher 1 catches "thrown by Timeout 1" | |
Catcher 1 returns | |
Timeout 2 throws | |
Catcher 2 catches "thrown by Timeout 2" | |
Catcher 2 throws | |
uncaughtException catches "thrown by Catcher 2" |
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 sys = require('sys'); | |
var http = require('http'); | |
var port = 3000; | |
http.createServer(dispatchRequest).listen(port); | |
sys.puts('Server running on port ' + port); | |
// This is the web framework, which wants to send |
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 express = require('express'); | |
var app = module.exports = express.createServer(); | |
app.get('/', function(req, res){ | |
process.nextTick(function () { | |
nonexistantFunc(); | |
}); | |
}); |
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
/** | |
# ms.js | |
No more painful `setTimeout(fn, 60 * 4 * 3 * 2 * 1 * Infinity * NaN * '☃')`. | |
ms('2d') // 172800000 | |
ms('1.5h') // 5400000 | |
ms('1h') // 3600000 | |
ms('1m') // 60000 |
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
// Helps with this problem: | |
// http://stackoverflow.com/questions/8059914/express-js-hbs-module-register-partials-from-hbs-file | |
var hbs = require('hbs'); | |
var fs = require('fs'); | |
var partialsDir = __dirname + '/../views/partials'; | |
var filenames = fs.readdirSync(partialsDir); |
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
$('button.accept-terms').click(function (e) { | |
$(e.target).attr('disabled', 'disabled'); | |
$.ajax({ | |
type: 'POST', | |
url: '/settings', | |
data: { | |
_csrf: window._csrf, | |
accept_terms: true | |
}, | |
success: function (data, textStatus, jqXHR) { |
OlderNewer