Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / hyperloglog.js
Created August 19, 2012 23:20
hyperloglog_test.js
/**
* Author - Shutupandcode - Terrance A. Snyder (http://www.shutupandcode.net & http://www.terranceasnyder.com)
* w/ http://stackoverflow.com/users/36174/actual
*
* HyperLogLog implementation ripped from:
* http://stackoverflow.com/questions/5990713/loglog-algorithm-for-counting-of-large-cardinalities
*
* However modifications made to allow for intersect, union, etc
* to allow for comparing two instances together.
*
@terrancesnyder
terrancesnyder / dispatch.jsp
Created March 3, 2012 17:28
Request Dispatcher "server transfer" method
<%@ page import="org.orbeon.oxf.util.WriterOutputStream" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.StringTokenizer" %>
<%@ page import="java.util.HashMap" %>
<%-- Example which will handle processing a seperate request and include the content back --%>
<%
out.flush();
final JspWriter myout = out;
// Example 1: This gets the current servlet context
@terrancesnyder
terrancesnyder / example.xml
Created February 9, 2012 23:40
Call Submit with User Arguments and Parameters
<xforms:submission id="orbeonCustomer-submission"
class="fr-service"
ref="instance('fr-service-request-instance')"
action="http://......./orbeonFormsManager/outstanding.action?userId={xxforms:instance('user-instance')/userId}&amp;accountNumber={xxforms:instance('user-instance')/accountNumber}"
method="get"
separator="&amp;"
serialization="application/xml"
mediatype="application/xml"
replace="instance"
xforms:url-type="resource"
@terrancesnyder
terrancesnyder / oracle-generate-numeric-range.sql
Created February 3, 2012 18:38
oracle generate numeric range
select shard
FROM (select 0 shard from dual) shards
MODEL
DIMENSION BY (shard)
MEASURES (shard v)
RULES UPSERT
(v[for shard from 0 to 100 increment 1] = 1)
order by 1;