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
#!/usr/bin/env node | |
// Example of how to fallback to alternative websocket library for old protocol clients | |
// see https://gist.github.com/1148686 | |
var http = require('http'), | |
WebSocketRequest = require('websocket').request, | |
ws = require('websocket-server'); | |
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 mongodb = require('mongodb'); | |
// This example selects all documents of a collection and checks if they should be displayed. | |
// 15 documents should be displayed, but I have to select all from the DB because maybe | |
// myCheckFunction returns true only for the last 15 elements selected (if any). | |
// So at some point (if I have seen enough documents) the DB can stop sending me documents, | |
// i.e. not fetch another batch of 30 documents in this case. | |
var db = new mongodb.Db('mydb', new mongodb.Server('localhost', 27017, {})); |
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 util = require('util') | |
, WebSocket = require('websocket-server').WebSocket; | |
var CONCURRENCY = 200; | |
var SERVER = 'ws://localhost:3000/'; | |
for (var i = 0; i < CONCURRENCY; i++) { | |
createConnection(); | |
} |
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 http = require('http') | |
, net = require('net') | |
, util = require('util') | |
, wsio = require('websocket.io'); | |
var server = http.createServer(function (req, res) { | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.end('ok'); | |
}); |
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
/** | |
* The client opens 10,000 connections to the server and sends one 10k message. | |
* Every minutes, 2,000 new connections are openend and 2,000 random connections | |
* are closed (equally distributed interval). | |
*/ | |
var util = require('util') | |
, WebSocket = require('ws'); | |
// Config |
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 WebSocket = require('ws') | |
// open 200 connections that close after 5 seconds | |
for (var i = 0; i < 200; i++) { openWs() } | |
function openWs() { | |
var ws = new WebSocket('ws://localhost:8080') | |
ws.on('open', function() { | |
ws.send('hello') | |
setTimeout(function() { ws.close(); }, 5000) |
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 with "node --expose_gc" | |
var weak = require('weak') | |
, util = require('util') | |
function MyObject () { | |
var self = this; | |
Object.defineProperty(this, 'color', { | |
get: function() { return 'red' } | |
}) |
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 http = require('http') | |
, weak = require('weak') | |
var server = http.createServer(function(req, res) { | |
if (req.method == 'GET') { | |
// GET | |
console.log('GET request') | |
weak(req, function() { console.log('GET request collected by GC') }) | |
res.end() |
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
#!/usr/bin/perl | |
$_=shift@ARGV;s/Mↂ/+9000/g;s/Mↁ/+4000/g;s/CM/+900/g;s/CD/+400/g;s/XC/+90/g;s/XL/+40/g;s/IX/+9/g;s/IV/+4/g;s/ↂ/+10000/g;s/ↁ/+5000/g;s/M/+1000/g;s/D/+500/g;s/C/+100/g;s/L/+50/g;s/X/+10/g;s/V/+5/g;s/I/+1/g;/^[0-9\+]*$/ or die;eval'print 0'.$_; |
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
#!/usr/bin/perl | |
$_=shift@ARGV;s/CM/+900/g;s/CD/+400/g;s/XC/+90/g;s/XL/+40/g;s/IX/+9/g;s/IV/+4/g;s/M/+1000/g;s/D/+500/g;s/C/+100/g;s/L/+50/g;s/X/+10/g;s/V/+5/g;s/I/+1/g;eval'print 0'.$_; |
OlderNewer