Skip to content

Instantly share code, notes, and snippets.

View squaremo's full-sized avatar
💭
how does computer

Michael Bridgen squaremo

💭
how does computer
View GitHub Profile
@squaremo
squaremo / consumer.py
Created February 26, 2014 12:37
Topic publisher / consumer
import pika
import sys
import logging
logging.basicConfig(level=logging.CRITICAL)
params = pika.URLParameters('amqp://guest:guest@localhost:25671/%2F')
conn = pika.BlockingConnection(params)
ch = conn.channel()
@squaremo
squaremo / ctl.sh
Last active August 29, 2015 13:56
Single-host clustering
NODE=rabbit$1
shift 1
rabbitmqctl -n "$NODE@$(hostname -s)" $*
@squaremo
squaremo / client.py
Created February 25, 2014 13:27
RabbitMQ primer RPC
import pika
import sys
import logging
logging.basicConfig(level=logging.CRITICAL)
params = pika.URLParameters('amqp://guest:guest@localhost:5672/%2F')
conn = pika.BlockingConnection(params)
ch = conn.channel()
@squaremo
squaremo / base_types.js
Last active December 27, 2015 18:59
Code snippets for AMQP codec post
var Octet = rangeInt('octet', 0, 255);
var ShortStr = label('shortstr',
transform(function(s) {
return s.substr(0, 255);
}, arb.Str));
var LongStr = label('longstr',
transform(
function(bytes) { return new Buffer(bytes); },
@squaremo
squaremo / stress.js
Created October 2, 2013 23:55
A variety of stress test for amqplib
var PassThrough = require('stream').PassThrough ||
require('readable-stream/passthrough');
var HWM = 100;
var tasks = new PassThrough({objectMode: true, highWaterMark: HWM});
var conn, ch;
var i = 0;
// Convert a promise-oriented API into a callback-oriented API
function identity(x) { return x; }
function slice(arrayish, arg1, arg2) {
return Array.prototype.slice.call(arrayish, arg1, arg2);
}
// Makes a transformer from promise-returning functions to
// callback-accepting functions.
@squaremo
squaremo / repl.js
Last active December 15, 2015 18:39
Examples of multiple dispatch in JavaScript
widgetize.method(Error, Object, function(err) {
return err;
});
render.method(Error, Function, function(err, append) {
append($('<span/>').addClass('error').text(err));
});
// A special value to represent values we're waiting for
function Waiting() {}
widgetize.method(Waiting, Object, function(wait) {
@squaremo
squaremo / constructor_inheritance.js
Last active July 24, 2021 06:23
Snippets for PMD post
function Bloop() { }
var bloop = new Bloop();
bloop.constructor === Bloop; // and indeed,
bloop.constructor === Bloop.prototype.constructor;
@squaremo
squaremo / eventS.js
Created September 10, 2012 19:42
Various ways of implementation stream and lazy-seq like things
// Actually you can hook #1 up as an event handler too, using the
// promise implementation:
function eventsS() {
var step = function(sync) {
return function(cons, nil) {
sync.then(function(cell) {
cons(cell.value, cell.tail);
});
}
@squaremo
squaremo / Push event.json
Created July 16, 2012 15:18
organisation events
{
"org": {
"login": "rabbitmq",
"gravatar_id": "d67216c2433a2f9e836e4491ff72a3ad",
"avatar_url": "https://secure.gravatar.com/avatar/d67216c2433a2f9e836e4491ff72a3ad?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png",
"id": 96669,
"url": "https://api.github.com/orgs/rabbitmq"
},
"type": "PushEvent",
"created_at": "2012-07-16T12:20:20Z",