Skip to content

Instantly share code, notes, and snippets.

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

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@mkuklis
mkuklis / gist:4015291
Created November 5, 2012 04:19
playing with erlang
% variables
One = 1.
Two = One + 1.
% atoms
atom.
'Hi I am an atom'.
another@_atom1.
@mkuklis
mkuklis / gist:3985606
Created October 31, 2012 07:27
scalable socket.io with redis and node-http-proxy
// balancer node
var httpProxy = require('http-proxy');
var uuid = require('node-uuid');
var Cookies = require('cookies');
var redis = require('redis');
var connect = require('connect');
var express = require('express');
var RedisStore = require('connect-redis')(express);
var redisClient = redis.createClient();
var port = 8000;
@mkuklis
mkuklis / Backbone.Service.js
Created October 21, 2012 19:16
backbone service for non restful api
Backbone.Service = function (options) {
this.options = options || {};
this.ctx = options.context || this;
this.endpoints = this.parseEndpoints(options.endpoints);
_(this.endpoints).each(this.createMethod, this);
};
Backbone.Service.prototype.parseEndpoints = function (endpoints) {
return _(endpoints).map(function (value, key) {
var endpoint = { name: key };
@mkuklis
mkuklis / promise.js
Created October 21, 2012 16:56
simple promise
function Promise(context) {
this.context = context || this;
this.success = [];
this.error = [];
}
Promise.prototype.then = function (success, error) {
if (success) {
if (this.resolved) {
success.apply(this.context, this.resolved);
@mkuklis
mkuklis / gist:3847147
Created October 7, 2012 04:54
bring redis up/down for testing
var exec = require('child_process').exec;
var redis = require("redis");
var when = require('when');
var client;
exports.startServer = function () {
exec('redis-server');
}
exports.stopServer = function () {
@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');
});
@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: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 / 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: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);