Skip to content

Instantly share code, notes, and snippets.

TBinaryProtocol.prototype.writeMessageBegin = function(name, type, seqid) {
if (this.strictWrite) {
this.writeI32(VERSION_1 | type);
this.writeString(name);
this.writeI32(seqid);
} else {
this.writeString(name);
this.writeByte(type);
this.writeI32(seqid);
}
@russellhaering
russellhaering / tls-double-callback.js
Created January 16, 2012 21:35
double callback introduced to node in 07c27e040eb41a1f564f1d92dbe1ad07b78f3a4e
var https = require('https');
function main() {
var fired = 0, req;
req = https.request({
host: 'localhost',
port: 8052,
path: '/',
method: 'GET'
PING google.com (74.125.224.112): 56 data bytes
64 bytes from 74.125.224.112: icmp_seq=0 ttl=57 time=550.263 ms
64 bytes from 74.125.224.112: icmp_seq=1 ttl=57 time=910.745 ms
64 bytes from 74.125.224.112: icmp_seq=2 ttl=57 time=874.949 ms
64 bytes from 74.125.224.112: icmp_seq=3 ttl=57 time=667.673 ms
64 bytes from 74.125.224.112: icmp_seq=4 ttl=57 time=429.829 ms
64 bytes from 74.125.224.112: icmp_seq=5 ttl=57 time=569.470 ms
64 bytes from 74.125.224.112: icmp_seq=6 ttl=57 time=759.054 ms
Request timeout for icmp_seq 7
64 bytes from 74.125.224.112: icmp_seq=7 ttl=57 time=1925.043 ms
@russellhaering
russellhaering / onidpw.py
Created September 27, 2011 18:04
Oregonstate ONID Password Cycler
#!/usr/bin/env python
#
# reset-onid.py - A script to allow you to keep your ONID password at Oregon
# State University. This script is (literally) untested and should not be used
# under any circumstances
#
# Dependencies:
# - httplib2
# - The 'pwgen' utility
#
@russellhaering
russellhaering / scribe.js
Created August 23, 2011 19:59
Scribe Result Code
// Thrift generated code
scribe_Log_result.prototype.write = function(output) {
output.writeStructBegin('scribe_Log_result');
if (this.success) {
output.writeFieldBegin('success', Thrift.Type.I32, 0);
output.writeI32(this.success);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
@russellhaering
russellhaering / uhohthrift.js
Created July 21, 2011 22:32
Node.js Thrift Server Exception Handling
/** This is what a thrift service implementation in Node.js _currently_ looks like */
var CURRENT_HANDLER = {
// On success, the return argument is passed as the only argument to the callback
HelloWorld: function(name, callback) {
callback("hello " + name);
},
// When something goes wrong, there is no way to get the exception back to the client
UhOhWorld: function(name, callback) {
var e = new ttypes.UhOhException("I can't do that " + name);
@russellhaering
russellhaering / sprintf.js
Created July 21, 2011 00:14
Fast sprintf() in Javascript
/**
* Note: this only currently supports the %s and %j formatters.
*
* The first call with any given formatter will be relatively slow, but every subsequent
* call with the same formatter should be very fast (in V8).
*/
var cache = {};
var SINGLE_QUOTE = new RegExp('\'', 'g');
@russellhaering
russellhaering / test.js
Created July 6, 2011 00:13
Stack Trace?
var fs = require('fs');
function foo(callback) {
fs.stat('foo', callback);
}
function bar(callback) {
foo(callback);
}
@russellhaering
russellhaering / defs.js
Created June 8, 2011 17:57
Cast Swiz Def Changes
// New style
/**
* @inheritdoc
*/
SigningRequest.prototype.getSerializerDef = function() {
return {
'name': {
src: 'name',
type: 'string'
},
@russellhaering
russellhaering / job-http.js
Created June 6, 2011 18:14
I hate jslint
function returnReadyJob(res, job) {
function onReady() {
job.removeListener('ready', onReady);
job.removeListener('error', onError);
returnSwiz(res, job);
}
function onError(err) {
job.removeListener('ready', onReady);
job.removeListener('error', onError);