Skip to content

Instantly share code, notes, and snippets.

View wankdanker's full-sized avatar

Dan VerWeire wankdanker

View GitHub Profile
@wankdanker
wankdanker / dgram-multicast.md
Created November 21, 2011 22:25
Links regarding dgram multicast

This page has Windows tools that can send and receive test multicast messages. With this tool, I have been able to run multiple instances of mcreceive.exe on the same machine. The both instances receive all messages sent by mcsend.exe.

This page has code which can be compiled on Linux (and other Unix?). Multiple instances can be run and they will not argue about listening on the same UDP port.

@wankdanker
wankdanker / SimpleCluster.js
Created December 22, 2011 15:25
A simple cluster module that re-spawns child processes that have died. Also reloads child processes when `require()`d script files have changed.
/*jslint node: true, maxerr: 50, indent: 4 */
"use strict";
var clusterInstance;
var SimpleCluster = module.exports = function () {
//there should only be one instance of this per process
if (clusterInstance) {
return clusterInstance;
@wankdanker
wankdanker / test-dgram-multicast-multi-process.js
Created January 27, 2012 22:57
test fix for dgram multicast test
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@wankdanker
wankdanker / bench-callback.js
Created March 2, 2012 16:15
Benchmark javascript callback functions - anonymous vs named
//Benchmark calling a function passing it an anonymous function vs passing it a named function
//
var iterations = 100000;
function testAnon(fn) {
console.time('test-anonymous-function');
for (var x = 0; x < iterations; x++) {
fn(function () {});
}
@wankdanker
wankdanker / client.js
Created April 11, 2012 22:11
quick-test node udp latency: start server.js, then start the client.js
var udp = require('dgram');
var s = udp.createSocket('udp4');
s.bind(27016, '127.0.0.1');
var t;
s.on('message', function(data, remote) {
var req = data.toString();
if (req == 'go-ahead') {
@wankdanker
wankdanker / gist:2400514
Created April 16, 2012 18:25
node-mysql-bindings-benchmarks + node-odbc
./bin/node-mysql-bindings-benchmark.js
Benchmarking CPP-MySQL:
**** Benchmark initialization time is 0.00s
**** 1000000 escapes in 0.17s (5882352/s)
**** 1000 sync reconnects in 0.09s (11111/s)
**** 10000 sync insertions in 0.16s (62500/s)
Benchmarking PHP-MySQL:
**** Benchmark initialization time is 0s
**** 1000000 escapes in 0.66s (1508394/s)
**** 1000 sync reconnects in 0.23s (4307/s)
@wankdanker
wankdanker / odbc-bench.c
Created April 16, 2012 20:57
benchmark minimal query using raw odbc
/*
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
@wankdanker
wankdanker / readstuff.js
Created November 16, 2012 23:56
for xp_prg
var prompt = require('prompt');
var result2 = [];
//not sure what this does so don't know when it should be called.
prompt.start();
function getData() {
prompt.get(['username', 'email'], function (err, result) {
if (err) { return onErr(err); }
console.log('Command-line input received:');
@wankdanker
wankdanker / README.md
Last active December 14, 2015 16:38
Generate a mac address based on FQDN

Install

curl https://gist.githubusercontent.com/wankdanker/2f676cc85f52fd471567/raw -o /usr/local/bin/gen-mac; chmod 755 /usr/local/bin/gen-mac
@wankdanker
wankdanker / broadcast.js
Created November 2, 2011 18:51
simple test cases for broadcast and multicast compatibility between node.js v0.4.x and v0.6.x
var dgram = require('dgram');
var socket = dgram.createSocket('udp4');
var testMessage = "[hello world] pid: " + process.pid;
var broadcastAddress = '255.255.255.255';
var broadcastPort = 5555;
socket.setBroadcast(true);
socket.bind(broadcastPort, '0.0.0.0');