Skip to content

Instantly share code, notes, and snippets.

View lance's full-sized avatar
🎯
Focusing

Lance Ball lance

🎯
Focusing
View GitHub Profile
var vertx = require('vertx');
var timeoutProxy = function(callback, delay) {
vertx.setTimer(delay, callback, Array.prototype.slice.call(2, arguments));
}
// Make the setTimeout function global if it doesn't exist already
setTimeout = (typeof setTimeout === 'function') ? setTimeout : timeoutProxy;
var thing = require('thing');
var http = require('vertx/http');
var server = http.createHttpServer();
server.requestHandler(function(request) {
request.response.putHeader('foo', 'bar');
request.response.end('bye!');
})
server.listen(8080);
@lance
lance / http_test.js
Created May 14, 2014 17:23
HttpClientRequestWriteEnd.js
testHttpClientRequestWrite: function() {
server.requestHandler(function(req) {
req.dataHandler(function(data) {
vassert.assertEquals('cheese fondue', data.toString());
req.response.end();
vassert.testComplete();
});
});
server.listen(port, "0.0.0.0", function(err, serv) {
vassert.assertTrue("Unexpected error: " + err, err === null);
@lance
lance / truthy.js
Last active August 29, 2015 14:01
([null]) ? true : false;
true
([null] == false) ? true : false;
true
([0]) ? true : false;
true
([0] == true) ? true : false;
false
@lance
lance / http_test.js
Created May 16, 2014 14:15
httpWriteSpec.js
testHttpClientRequestWrite: function() {
var test_headers = {
'x-custom-header': 'A custom header'
};
var test_options = {
port: 9999,
host: 'localhost',
method: 'GET',
path: '/some/path?with=a+query+string',
headers: test_headers
var util = NativeRequire.require('util');
var EventEmitter = NativeRequire.require('events').EventEmitter;
module.exports.makeEventEmitter = function(ctor) {
util._extend(ctor.prototype, EventEmitter.prototype);
};
module.exports.vertxHandler = function(handler, resultConverter) {
return function(future) {
if (handler) {
var util = NativeRequire.require('util');
var EventEmitter = NativeRequire.require('events').EventEmitter;
module.exports.makeEventEmitter = function(ctor) {
util._extend(ctor.prototype, EventEmitter.prototype);
};
module.exports.vertxHandler = function(handler, resultConverter) {
return function(future) {
if (handler) {
function delegateFunction(f) {
return function() {
var args = Array.prototype.slice.call(arguments);
var last = args.pop();
if (typeof last === 'function') {
args.push(nodyn.vertxHandler(last));
} else if (last !== undefined) {
args.push(last);
}
f.apply(f, args);
// When vertx file system functions mirror node file system
// functions, we can use this high-order function to
// delegate. It passes args unmolested into the vertx
// API, and provides a possibly converted return value
// (or callback arg). If the type/order of function
// arguments don't match up between vertx and node, then
// don't use this function.
function delegateFunction(f, converter) {
return function() {
if (!converter) { converter = function(result) { return result; }; }
@lance
lance / my_face.md
Last active August 29, 2015 14:02
These are my words that I spoke at Mike Ball's memorial service. I read this poem, and spoke about family.

In addition to reading this poem, I was asked to speak a few words about family. Mike was my uncle.

This poem speaks to me of finding and accepting who you are, because of (or in spite of) the face, the name, the family you are given. It is about acceptance.

There is a famous quote by Leo Tolstoy. I think it is the opening line of Anna Karenina. I am paraphrasing: "Every happy family is exactly the same. But each unhappy family is unhappy in its own unique way." I like this quote. But I don't really think it's true. I think ALL families are unhappy in some way. But that doesn't make them bad, or wrong. It just makes them real. It gives shape and contour to the mask of the face you are given.