Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
jugglinmike / redisstore.js
Created October 27, 2012 23:08
Socket.io redis store
socketServer.set("store", new socketIo.RedisStore({
redisPub: redis.createClient(),
redisSub: redis.createClient(),
redisClient: redis.createClient()
}));
@jugglinmike
jugglinmike / transport.js
Created October 27, 2012 23:16
Modified Socket.io Transport.end
Transport.prototype.end = function (reason) {
console.log("Transport.end", { reason: reason, "this.disconnected": this.disconnected });
if (!this.disconnected) {
this.log.info('transport end (' + reason + ')');
var local = this.manager.transports[this.id];
this.close();
this.clearTimeouts();
this.disconnected = true;
@jugglinmike
jugglinmike / sct.js
Created October 27, 2012 23:26
Socket.io - Cluster Test Script
var cluster = require("cluster");
var os = require("os");
var numCPUs = os.cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
@jugglinmike
jugglinmike / bizarre.js
Created December 16, 2012 01:59
Adventures in bizarre JavaScript
Array.constructor.apply(null, { length: 2, 1: "alert(undefined)" })("Nu-uh!")
var mikeEval = function(code) { return Array.constructor("return " + code)(); }
@jugglinmike
jugglinmike / fizzbuzz.js
Last active February 20, 2016 16:54
FizzBuzz
(function() {
var fb, i;
(fb = "Fizz Buzz ".split(" ")).unshift(fb.join(""));
for (i = 1; i < 101; ++i) {
console.log(fb[(i % 3 && 2) + (i % 5 && 1)] || i);
}
}());
@jugglinmike
jugglinmike / phonetic.js
Last active December 14, 2015 20:19
A script to expand acronyms in text to their phonetic equivalents
// phonetic.js
// A script to expand acronyms in text to their phonetic equivalents
var defaultInput = "I am the illest MC that you ever SAW";
var sounds = {
A: "ay",
B: "bee",
C: "see",
D: "dee",
E: "ee",
F: "eff",
@jugglinmike
jugglinmike / helper.rb
Created March 16, 2013 22:55
Using nanoc to generate a cache-busting URL for external assets.
# Given an item identifier, generate its fully-qualified URL along with the
# item's hash as a query string parameter. Omit this cache-busting mechanism
# in development environments so that HTML documents including this resource
# aren't re-rendered with every change to the asset.
def cache_bust_path( identifier )
static = StorageHelper::static
item = static[:assets][identifier]
if !item
return identifier
end

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@jugglinmike
jugglinmike / create.js
Last active December 16, 2015 17:29
Function.prototype.create
// Function.prototype.create
(function() {
var Surrogate = function() {};
Function.prototype.create = function() {
if (this.__inst) {
return this.__inst;
}
@jugglinmike
jugglinmike / bullet-app.js
Last active December 19, 2015 19:09
Bullet Charts with d3.chart
(function() {
"use strict";
d3.json("bullets.json", function(error, data) {
var myChart = d3.select("body").chart("Bullets", {
seriesCount: data.length
});