Skip to content

Instantly share code, notes, and snippets.

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

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@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: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: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: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: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:3266984
Created August 5, 2012 20:15
resource.js
var Resource = (function () {
// static API
var api = (function () {
this.models = [];
this.add = function (model) {
// TODO: make model a real model
this.models.push(model);
@mkuklis
mkuklis / zepto.simulate.js
Created September 10, 2012 02:55
zepto.simulate.js
(function ($) {
var matchers = {
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
};
var defaults = {
x: 0,
y: 0,
@mkuklis
mkuklis / gist:3747385
Created September 19, 2012 02:53
CORS with express, redis as session store and zepto
// server
// redis client
var redisClient = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
redisClient.auth(process.env.REDIS_PASS);
// redis session store
var session = {
secret: 'your_secret',
store: new RedisStore({ client: redisClient })
@mkuklis
mkuklis / gist:3757282
Created September 20, 2012 17:38
elementFromPoint
(function ($) {
$.elementFromPoint = function (x, y) {
var moved = false;
var yo = window.pageYOffset;
var xo = window.pageXOffset;
var w = window.innerWidth;
var h = window.innerHeight;
if (yo > 0) {
@mkuklis
mkuklis / gist:3813128
Created October 1, 2012 17:17
zepto click and tap events for mobile & desktop
if ('ontouchstart' in window) {
// turn off click event
$(document)
.on('click', 'a', function(e) {
e.preventDefault();
e.stopPropagation();
})
.on('tap', 'a', function(e) {
window.location.href = $(e.currentTarget).attr('href');
});