Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
jugglinmike / boaz_leverage.js
Created June 15, 2011 19:45
Using the Strategy pattern in JavaScript
$.each( buttons, function( propertyName, button ) {
$('<button>', {
html: button.label,
id: propertyName
})
.bind('click', button.action)
.appendTo( 'nav' );
});
@jugglinmike
jugglinmike / background-toggle.js
Created August 4, 2011 00:30
Chrome User-Agent String Modification
var listenerIsActive = true,
requestFilter = {
urls: [ "<all_urls>" ]
},
extraInfoSpec = ['requestHeaders','blocking'],
handler = function( details ) {
var headers = details.requestHeaders,
blockingResponse = {};
@jugglinmike
jugglinmike / memoize.js
Created August 27, 2011 16:39
Memoizing Example for "Avoiding the Quirks"
// Examples based on those given in
// "Avoiding The Quirks: Lessons From A JavaScript Code Review"
// by Addy Osmani
// http://addyosmani.com/blog/lessons-from-a-javascript-code-review/
// Branching at runtime with memoization
// (wordy version)
var utils = {
getXHR: function() {
var subject = "[Subject] is dead, long live [Subject]",
regex = /\[Subject\]/g;
while( regex.test(subject) ) {
subject = subject.replace( regex, subject );
console.log( subject );
}
// Warning... I killed node with this.
// FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory
​do {
var m = 23;
}
console.log( typeof m );​ // ???
@jugglinmike
jugglinmike / scoped.html
Created June 4, 2012 14:37
Bocoup.com: Future of 3PJS
<div class="container">
<style scoped>
p { color: red; }
</style>
<p>This paragraph has red text.<p>
</div>
<p>This paragraph does not.</p>
@jugglinmike
jugglinmike / app.py
Created July 2, 2012 18:35
Sandbox Post-receive Handler
from flask import Flask
from flask import request
import git
import json
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Hello, world!"
@jugglinmike
jugglinmike / quine.js
Created July 12, 2012 13:19
JavaSript Quine
var g = function () { console.log("var g = " + this.toString() + "; g.call(g);"); }; g.call(g);
@jugglinmike
jugglinmike / youtube-comments.user.js
Created August 14, 2012 12:58 — forked from tbranyen/youtube-comments.user.js
A user script for removing bullshit YouTube comments.
// ==UserScript==
// @name RemoveYouTubeComments
// @description Remove bullshit YouTube comments.
// @match http://www.youtube.com/*
// @author Tim Branyen
// @version 1.0
// ==/UserScript==
// Find the comments view element.
var commentsView = document.getElementById("comments-view");
@jugglinmike
jugglinmike / server.js
Created October 27, 2012 18:30
Node.js's "cluster" module usage
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();
}