Skip to content

Instantly share code, notes, and snippets.

View suprememoocow's full-sized avatar

Andrew Newdigate suprememoocow

View GitHub Profile
@suprememoocow
suprememoocow / init.sls
Last active August 29, 2015 13:56
Upgrade npm to 1.4.4 with Salt
# git is needed for npm if you have git references
build-essential:
pkg:
- installed
npm-custom:
git.latest:
- name: https://github.com/isaacs/npm.git
- target: /opt/npm
- rev: v1.4.4
@suprememoocow
suprememoocow / install.sh
Created April 7, 2014 22:33
Update OpenSSL to 1.0.1g using Ansible
#!/bin/bash
# roles/openssl/files/install.sh
wget https://www.openssl.org/source/openssl-1.0.1g.tar.gz -O /tmp/openssl-1.0.1g.tar.gz
cd /tmp
tar -xvzf openssl-1.0.1g.tar.gz
cd openssl-1.0.1g
@suprememoocow
suprememoocow / redis-sentinel-workout.sh
Created May 8, 2014 08:30
Redis sentinel failover workout script
#!/bin/bash
set -e
TIME=30
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
function ctrl_c() {
echo + Stopping service 1
@suprememoocow
suprememoocow / nodeserver.conf
Created October 22, 2014 14:11
Node upstart script
start on starting gitter-web ## The parent upstart service, so we can start and stop groups together
stop on stopping gitter-web
# Respawn, but no too much
respawn
respawn limit 10 5
# Give the process 20 seconds to shutdown properly before resorting to SIGKILL
kill timeout 20
@suprememoocow
suprememoocow / index.js
Created January 19, 2015 17:12
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Rebuild to run it on the right
var b = require('backbone')
// Start a server
var Faye = require('faye'),
server = new Faye.NodeAdapter({mount: '/'});
server.listen(8000);
// Create a client and subscribe to a channel
var client = new Faye.Client('http://localhost:8000/');
client.subscribe('/messages', function(message) { alert('Got a message: ' + message.text);
});
var fayeServer = new faye.NodeAdapter({mount: '/faye', timeout: 45});
fayeServer.attach(httpServer);
// This method will send realtime notifications to the faye clients
function notifyClients(method, model, url) {
bayeux.getClient().publish(url, {
method: method,
body: model.toJSON()
});
}
// Attach events to the mongoose schema. Since the default mongoose middleware makes it difficult to
// distinguish between a create and an update event, we use a small utility that helps us to do that.
var fayeClient = new Faye.Client('/faye');
var LiveCollection = Backbone.Collection.extend({
constructor: function(models, options) {
Backbone.Collection.prototype.constructor.call(this, models, options);
this.subscription = fayeClient.subscribe(this.url, this._fayeEvent, this);
},
_fayeEvent: function(message) {
var LiveCollection = Backbone.Collection.extend({
...
_createEvent: function(body) {
...
// Look to see if this collection has any outstanding creates...
var idAttribute = this.model.prototype.idAttribute;
var unsaved = this.filter(function(model) {
return !model.id;