Skip to content

Instantly share code, notes, and snippets.

View mkuklis's full-sized avatar
🏃‍♂️

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@mkuklis
mkuklis / gist:3036302
Created July 2, 2012 23:15
profilejs
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);
}
@mkuklis
mkuklis / gist:2592550
Created May 4, 2012 06:18
Leonardo + Box2D = Bonnet.js
(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,
@mkuklis
mkuklis / gist:2510679
Created April 27, 2012 16:43
underscore _.filterAll
(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;
});
@mkuklis
mkuklis / gist:2422811
Created April 19, 2012 18:22
playing with phantomjs, pjscrape and jQuery :)
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;
}
@mkuklis
mkuklis / gist:2347864
Created April 10, 2012 01:48
exploring different plugin initialization options
// version 1
function A() {
this.init();
}
A.prototype = {
init: function () {
A.inits.forEach(function (item) {
item.call(this);
}, this);
@mkuklis
mkuklis / gist:2321307
Created April 6, 2012 16:56
PhoneGap JQM Initialization
var jqmReady = $.Deferred(),
pgReady = $.Deferred();
// jqm ready
$(document).bind("mobileinit", jqmReady.resolve);
// phonegap ready
document.addEventListener("deviceready", pgReady.resolve, false);
// all ready :)
@mkuklis
mkuklis / gist:2046692
Created March 15, 2012 20:28
playing with deferred objects
var a = function () {
var obj = $.Deferred();
setTimeout(function () {
console.log('resolving a');
obj.resolve({a: 1});
}, 1000);
return obj;
}
var b = function () {
@mkuklis
mkuklis / gist:1552169
Created January 2, 2012 21:19
more experiments with canvas
// 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;
@mkuklis
mkuklis / gist:1511032
Created December 22, 2011 17:09
mercurial push to default repo
# create file called hgrc in your project under.hg and add:
[paths]
default-push = ssh://[email protected]/path
@mkuklis
mkuklis / gist:1384978
Created November 22, 2011 05:33
playing around with canvas :)
(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) {