Skip to content

Instantly share code, notes, and snippets.

@terrancesnyder
terrancesnyder / ec2-dynamic-discovery.sh
Created August 27, 2012 14:32
discovery of amazon instances by tag
#!/bin/sh
export JAVA_HOME=/opt/java/current
export EC2_PRIVATE_KEY=/home/ubuntu/cloudstrap.io/modules/amazon/files/certs/pk.pem
export EC2_CERT=/home/ubuntu/cloudstrap.io/modules/amazon/files/certs/cert.pem
export EC2_HOME=/opt/ec2-api-tools-1.5.3.1
export PATH=$PATH:$EC2_HOME/bin
ec2-describe-tags --filter "resource-type=instance" --filter "key=node" | while read x;
do
node=`echo $x | awk '{print $5}'`
@terrancesnyder
terrancesnyder / node-0mq-ctrl-c.js
Created September 7, 2012 21:14
Handling Ctrl-C cleanly in Node.js
// Show how to handle Ctrl+C in Node.js
var zmq = require('zmq')
, socket = zmq.createSocket('rep');
socket.on('message', function(buf) {
// echo request back
socket.send(buf);
});
@terrancesnyder
terrancesnyder / index.html
Created September 13, 2012 22:27 — forked from ovaillancourt/index.html
Socket io + static file serving with connect
<!-- This should be served by your server -->
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
@terrancesnyder
terrancesnyder / self-assembling-architecture.js
Created October 23, 2012 02:04
Interesting concept for self-assembling nodes
infrastructure
.discover('solr')
.enter(function(instance) { // when a new instance has announced itself or come online again
// instance.port
// instance.core
// instance.ip
// instance.ttl
})
.exit(function(instance) { // when an instance has left
// when an instance has left we can now unregister it
@terrancesnyder
terrancesnyder / pub.js
Created October 23, 2012 18:22
Example for publishing infrastructure with nodejs + zmq
var cloudfront = require('./cloudfront.io');
var infrastructure = new cloudfront.infrastructure();
// announce that there is a memcache instance available
// to the collective
infrastructure.announce('memcache', {
ip: '<yourip>',
port: '<yourport>',
tag: '<sometag you care about>'
}, 5000);
@terrancesnyder
terrancesnyder / sub.js
Created October 23, 2012 18:31
Example of subscriber to infrastructure services
var cloudfront = require('./cloudfront.io');
var infrastructure = new cloudfront.infrastructure();
infrastructure.discover('memcache')
.enter(function(instance, done) {
// do something when a new memcache instance joins
done(); // callback required for ATOMIC acknowledgement (same concept as QUnit)
})
.exit(function(instance, done) {
// do something when an instance has leaves
@terrancesnyder
terrancesnyder / script.sh
Created October 24, 2012 21:28
Apache Bench w/ Extract Cookie
ab -v 2 -c 30 -n 100 "http://www.yourdomain.com/" | grep -ohE "Set-Cookie: jspsession=..........................."
@terrancesnyder
terrancesnyder / producer.js
Created November 21, 2012 20:19
Producer Example NodeJS (225k/second without a consumer, 185k with a consumer)
var zmq = require('zmq'),
sock = zmq.socket('push'),
_ = require('underscore');
// increase swap for high water mark
zmq.options.swap = 1024;
zmq.options.hwm = 0;
// zmq.options.rate = 800000;
sock.bind('tcp://127.0.0.1:3000', function(err) {
@terrancesnyder
terrancesnyder / consumer.js
Created November 21, 2012 20:20
NodeJS ZeroMQ Consumer Example used with Issue #110 on ZMQ
var zmq = require('zmq')
, sock = zmq.socket('pull');
// increase swap for high water mark
zmq.options.swap = 1024;
zmq.options.hwm = 0;
// zmq.options.rate = 800000;
sock.connect('tcp://127.0.0.1:3000');
console.log('Worker connected to port 3000');
@terrancesnyder
terrancesnyder / gist:4366869
Created December 24, 2012 00:25
Bug with pentaho output servlet
var out = _step_.getTrans().getServletPrintWriter();
out.println("<H1>");
out.println("Hello World!");
out.println("ときょ 東京 コーヒー");
out.println("</H1>");