Skip to content

Instantly share code, notes, and snippets.

View brettkiefer's full-sized avatar

Brett Kiefer brettkiefer

View GitHub Profile
@brettkiefer
brettkiefer / ssl_hang.js
Created February 25, 2011 16:55
Running this (sudo if you want port 443) with node v0.4.1 and hard-refreshing the page several times causes a request to hang
We couldn’t find that file to show.
@brettkiefer
brettkiefer / ssl_hang.js
Created March 15, 2011 20:14
Running this causes an ssl hang within a few hard reloads.
// Assumes a privatekey.pem and certificate.pem in this directory
// Probably have to run as root to start on port 443
// See http://www.silassewell.com/blog/2010/06/03/node-js-https-ssl-server-example/ for ssl cert setup
var https = require('https');
var fs = require('fs');
var url = require('url');
var sslOpts = {
key: fs.readFileSync(__dirname + '/privatekey.pem'),
cert: fs.readFileSync(__dirname + '/certificate.pem')
@brettkiefer
brettkiefer / node mongodb write-then-read
Created April 18, 2011 17:48
Shows one case where parallel connections to MongoDB give a substantial speedup
// Modified from node-mongodb-native example
sys = require("sys");
var Db = require('mongodb').Db,
Connection = require('mongodb').Connection,
Server = require('mongodb').Server,
// BSON = require('mongodb').BSONPure;
BSON = require('mongodb').BSONNative;
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
@brettkiefer
brettkiefer / test_deep_object.js
Created April 19, 2011 16:26
Put a 1MB string at the lowest level of a 700-level deep object, then serialize and deserialize it, shows node-mongodb-native dbson deserialization performance issue.
require.paths.unshift("../../lib");
var sys = require('sys'),
Buffer = require('buffer').Buffer,
BSON = require('./bson').BSON,
Buffer = require('buffer').Buffer,
BSONJS = require('mongodb/bson/bson').BSON,
BinaryParser = require('mongodb/bson/binary_parser').BinaryParser,
Long = require('mongodb/goog/math/long').Long,
ObjectID = require('mongodb/bson/bson').ObjectID,
@brettkiefer
brettkiefer / crashMongo.js
Created July 8, 2011 14:12
Crashes MongoDB 1.8.1
var mongoose = require('mongoose');
var IndexedGuy = new mongoose.Schema({
name: { type: String, index: true }
});
mongoose.model('IndexedGuy', IndexedGuy);
mongoose.connect("mongodb://localhost/test-crash");
mongoose.model('IndexedGuy').find({
_id: {
@brettkiefer
brettkiefer / connected.html
Created July 12, 2011 19:21
When event propagation is stopped, mousedown events are incorrectly stuck in the 'handled' state in jquery 1.8.14
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Sortable - Connect lists</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css">
<style>
#sortable1, #sortable2 { list-style-type: none; margin: 0; padding: 0; float: left; margin-right: 10px; }
@brettkiefer
brettkiefer / socket.io.patch
Created April 20, 2012 12:33
Our socket.io patches
--- a/socket.io/lib/manager.js Mon Nov 28 10:46:16 2011 -0500
+++ b/socket.io/lib/manager.js Mon Nov 28 10:49:24 2011 -0500
@@ -466,12 +466,13 @@
* @api private
*/
-Manager.prototype.onClientDisconnect = function (id, reason) {
+Manager.prototype.onClientDisconnect = function (id, reason, local) {
for (var name in this.namespaces) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id][name] !== 'undefined');
@brettkiefer
brettkiefer / big.js
Created June 5, 2012 20:12
problems with Mongoose when we have lots of embedded docs
var mongoose = require('../')
var fs = require('fs')
var Schema = mongoose.Schema;
CheckItem = new Schema({
name: { type: String },
type: { type: String },
pos: { type: Number },
});
@brettkiefer
brettkiefer / test.js
Created December 12, 2012 18:43
This is a tiny adaptation of the cluster example at http://nodejs.org/api/cluster.html to illustrate the problem i'm seeing in https://github.com/joyent/node/issues/3241
// a tiny adaptation of the cluster example at http://nodejs.org/api/cluster.html
// 1. save as test.js
// 2. run with "./node test.js > pid.log"
// 3. from another shell do "siege -t1m -c 50 http://localhost:8000"
// 5. wait for the siege to finish
// 6. ctrl-c the node process
// 7. sort pid.log | uniq -c
// The left side is # of requests served, the right side is pid.
// If it's balanced (as it is for me on the 2.6.32 linux kernel) then yay!
{
"coffeescript_error": {
"level": "error"
},
"duplicate_key": {
"level": "error"
},
"empty_constructor_needs_parens": {
"level": "error"
},