Skip to content

Instantly share code, notes, and snippets.

Brett Kiefer brettkiefer

  • Trello, Inc.
  • United States
Block or report user

Report or block brettkiefer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@brettkiefer
brettkiefer / repeatCounts.js
Created Oct 23, 2017
Demonstrate a failure to reconnect to a MongoDB replicaset when it loses a primary
View repeatCounts.js
// Run `npm i mongo` and run this test program after filling in the variables
// below. Run it against a replicaset with a sharded collection, with your
// MongoS process running on the same host as the script.
// You should // see start and finish messages from fxCountWithLog.
// Now do an rs.stepDown() on the replicaset primary. You should see an error
// message and the script should continue. So that's fine.
// Wait until the Replicaset settles down. Now on the new
// replicaset primary, do:
View Fog Creek coffeelint.json
{
"coffeescript_error": {
"level": "error"
},
"duplicate_key": {
"level": "error"
},
"empty_constructor_needs_parens": {
"level": "error"
},
@brettkiefer
brettkiefer / test.js
Created Dec 12, 2012
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
View test.js
// 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!
@brettkiefer
brettkiefer / big.js
Created Jun 5, 2012
problems with Mongoose when we have lots of embedded docs
View big.js
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 / socket.io.patch
Created Apr 20, 2012
Our socket.io patches
View socket.io.patch
--- 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 / connected.html
Created Jul 12, 2011
When event propagation is stopped, mousedown events are incorrectly stuck in the 'handled' state in jquery 1.8.14
View connected.html
<!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 / crashMongo.js
Created Jul 8, 2011
Crashes MongoDB 1.8.1
View crashMongo.js
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 / test_deep_object.js
Created Apr 19, 2011
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.
View test_deep_object.js
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 / node mongodb write-then-read
Created Apr 18, 2011
Shows one case where parallel connections to MongoDB give a substantial speedup
View node mongodb write-then-read
// 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 / ssl_hang.js
Created Mar 15, 2011
Running this causes an ssl hang within a few hard reloads.
View ssl_hang.js
// 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')
You can’t perform that action at this time.