Skip to content

Instantly share code, notes, and snippets.

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

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@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 / 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 / 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 / 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 / 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:4039471
Created November 8, 2012 15:28
making interaction with WebSQL easier
(function () {
"use strict";
/**
* DB constructor
*
* @param {Object} options
* @param {Function} callback
*/
@mkuklis
mkuklis / gist:4039482
Created November 8, 2012 15:31
logger.js
(function () {
"use strict";
var Logger = this.Logger = function ($el) {
this.$logger = $el;
this.timers = {};
}
Logger.prototype.stop = function (label) {
@mkuklis
mkuklis / gist:4056724
Created November 11, 2012 23:36
NamedViewSelector
//viewport for https://github.com/scttnlsn/backbone.viewkit
var NamedViewSelector = Backbone.ViewKit.ViewPort.extend({
constructor: function (options) {
options || (options = {});
this._views = options.views || {};
_.each(this._views, function(view) {
view.viewSelector = this;
}, this);
@mkuklis
mkuklis / gist:4186901
Created December 2, 2012 04:01
inheritance and Object.create
// resources gathered around inheritance and Object.create
// http://ericleads.com/2012/09/stop-using-constructor-functions-in-javascript/
// https://speakerdeck.com/anguscroll/parlez-vous-javascript
// http://dailyjs.com/2012/06/04/js101-object-create/
// inheritance via prototype
// both constructors A, B are initialized
function A() {
console.log("init A");
this.log = "A";
@mkuklis
mkuklis / gist:4226014
Created December 6, 2012 16:56
approach to client-side modules
// modules (one per file)
(function (namespace) {
"use strict";
// implementation
})(namespace);
// files.js (loaded in dev)