Skip to content

Instantly share code, notes, and snippets.

@broofa
broofa / robot.js
Created December 5, 2012 02:05
Broobot
var Robot = function(robot) {};
var ds = 1;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.rotateCannon(ds++);
robot.fire();
@broofa
broofa / jsscore.js
Created July 5, 2012 22:05
JS-Score Reference Implementation
/**
* Compute a jsscore for the current JS environment
*
* @param n (Number) Number of iterations to run. For best results this value
* should be selected such that the run time is between 0.1 and
* 0.5 seconds. The default (1,000,000) will fall well short of
* this on modern devices. This is by design so as to prevent
* unintentional CPU contention, but will likely yield inaccurate
* results.
*
apply: (Prototype.Browser.IE ? function(o, a) {
a = a || [];
switch (a.length) {
case 0: return this.call( o);// \ "FUUU...!"
case 1: return this.call( o,a[0]);// \ _
case 2: return this.call( o,a[0],a[1]);// \ \o
case 3: return this.call( o,a[0],a[1],a[2]);// /\_
case 4: return this.call( o,a[0],a[1],a[2],a[3]);// \ /\
case 5: return this.call( o,a[0],a[1],a[2],a[3],a[4]);// > /
case 6: return this.call( o,a[0],a[1],a[2],a[3],a[4],a[5]);// >
@broofa
broofa / gist:1071842
Created July 8, 2011 13:36
Differential Scrollifier Bookmarklet
== THE BOOKMARKLET ==
javascript: (function(){var a=function(s){return document.querySelectorAll(s)[0].style;},b=JX.copy;b(a('.differential-add-comment-panel h1'),{display:'none'});b(a('.differential-add-comment-panel'),{position:'fixed',bottom:'0px',width:'100%',zIndex:'100',overflow:'auto',maxHeight:'400px'});b(a('.differential-primary-pane'),{paddingBottom:'445px'});})()
== FORMATTED SOURCE ==
(function() {
var a = function(s) {
return document.querySelectorAll(s)[0].style;
}, b = JX.copy;
(function () {
var a, b, c;
function d() {}
// Is there an object, "???" that will let us enumerate thru
// the locals, "a", "b", "c", and "d"?
for (var k in ???) {
}
})()
var util = require('util');
var fs = require('fs');
var data = [
'/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcH',
'Bw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/',
'2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e',
'Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAAQABADASIAAhEBAxEB/8QA',
'HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF',
'BAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK',
server.addListener('request', function(req, res) {
var chunks = [], bytes = 0;
req.addListener('data', function(chunk) {
// Gather up chunks & track total data length
chunks.push(chunk);
bytes += chunk.length;
});
// "req.getBody(encoding)" returns the body string
function createNamedFunction() {
var _cnf = Array.prototype.slice.call(arguments, 0);
_cnf.name = _cnf.shift();
_cnf.code = _cnf.pop();
return new Function('return function NAME(ARGS) {CODE}'.
replace('NAME', _cnf.name).
replace('ARGS', _cnf.join(',')).
replace('CODE', _cnf.code))();
}
// Add a CLF logger
function logCLF(req, res) {
var log = [
req.connection.remoteAddress, // client IP
'-', // RFC 1413 identity
'-', // user id
'[' + new Date().toUTCString() + ']', // date
'"' + req.method + ' ' + req.url + '"', // request line
res.statusCode, // response code
'-' // response size (bytes)
From d84a19d450ba485e5508241f96c6e504a78a8cdd Mon Sep 17 00:00:00 2001
From: Robert Kieffer <robert@broofa.com>
Date: Fri, 26 Mar 2010 04:04:06 -0700
Subject: [PATCH] - Add support for OutgoingMessage#statusCode
- OutgoingMessage#close() emits 'close' event
- Add missing semicolons in various spots
---
lib/http.js | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)