This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function profile(methods, ctx) { | |
ctx = ctx || this; | |
for (var i = 0, l = methods.length; i < l; i++) { | |
(function(name) { | |
var method = ctx[name]; | |
ctx[name] = function () { | |
console.time(name); | |
method.apply(this, arguments); | |
console.timeEnd(name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (b2d, L) { | |
// Box2d shortcuts | |
var b2Vec2 = b2d.Common.Math.b2Vec2, | |
b2BodyDef = b2d.Dynamics.b2BodyDef, | |
b2Body = b2d.Dynamics.b2Body, | |
b2FixtureDef = b2d.Dynamics.b2FixtureDef, | |
b2Fixture = b2d.Dynamics.b2Fixture, | |
b2World = b2d.Dynamics.b2World, | |
b2PolygonShape = b2d.Collision.Shapes.b2PolygonShape, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (_, slice) { | |
_.filterAll = function (data) { | |
var filters = slice.call(arguments, 1); | |
return _.filter(data, function (item) { | |
var found = true; | |
for (var i = 0, l = filters.length; i < l; i++) { | |
found &= filters[i](item); | |
} | |
return found; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pjs.addSuite({ | |
url: 'http://ithaca.craigslist.org/apa/', | |
scraper: function () { | |
var listings = []; | |
$('blockquote p a').each(function () { | |
var item = $(this); | |
listings.push({url: item.attr('href'), text: item.text()}); | |
}); | |
return listings; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// version 1 | |
function A() { | |
this.init(); | |
} | |
A.prototype = { | |
init: function () { | |
A.inits.forEach(function (item) { | |
item.call(this); | |
}, this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jqmReady = $.Deferred(), | |
pgReady = $.Deferred(); | |
// jqm ready | |
$(document).bind("mobileinit", jqmReady.resolve); | |
// phonegap ready | |
document.addEventListener("deviceready", pgReady.resolve, false); | |
// all ready :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = function () { | |
var obj = $.Deferred(); | |
setTimeout(function () { | |
console.log('resolving a'); | |
obj.resolve({a: 1}); | |
}, 1000); | |
return obj; | |
} | |
var b = function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// demo: http://jsfiddle.net/7wG3a/14/ | |
var c = document.getElementById('canvas'); | |
var ctx = c.getContext('2d'); | |
var drawing = false, dx, dy; | |
var x = 100, y = 100, w = 100, h = 100; | |
c.onmousedown = function (e) { | |
dx = e.clientX - x; | |
dy = e.clientY - y; | |
drawing = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create file called hgrc in your project under.hg and add: | |
[paths] | |
default-push = ssh://[email protected]/path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
// global | |
var w = this | |
, d = w.document | |
// valid attributes | |
, vattrs = {x:1,y:1,cx:1,cy:1,r:1,w:1,h:1,fill:1,path:1} | |
// path commands | |
, pathCommands = { | |
M: function (v) { |