Skip to content

Instantly share code, notes, and snippets.

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

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@mkuklis
mkuklis / gist:1022325
Created June 13, 2011 04:46
falsy values in JavaScript
6 falsy values in JS:
- false
- null
- undefined
- '' // empty string
- 0 // number 0
- NaN
all other values are truthy (including "false")
@mkuklis
mkuklis / gist:1024340
Created June 14, 2011 04:42
Douglas Crockford's method helper
Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
return this;
}
};
@mkuklis
mkuklis / gist:1024381
Created June 14, 2011 05:35
Douglas Crockford's functional constructor
var constructor = function (spec, my) {
var that, other private instance variables;
my = my || {};
Add shared variables and functions to my
that = a new object;
Add privileged methods to that
return that;
@mkuklis
mkuklis / gist:1024385
Created June 14, 2011 05:37
Douglas Crockford's memoizer
var memoizer = function (memo, formula) {
var recur = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = formula(recur, n); memo[n] = result;
}
return result;
};
return recur;
};
@mkuklis
mkuklis / gist:1027738
Created June 15, 2011 18:25
JavaScript borrow method pattern
var foo1 = {
name: "hello from foo1",
print: function () {
return this.name;
}
};
var foo2 = {
name: "hello from foo2"
};
@mkuklis
mkuklis / gist:1030922
Created June 17, 2011 05:35
JavaScript test for Array
if (typeof Array.isArray === "undefined") {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) === "[object Array]";
};
}
@mkuklis
mkuklis / gist:1030949
Created June 17, 2011 06:19
lazy function definition pattern in JavaScript
var doThisDoThat = function () {
console.log("do this");
doThisDoThat = function () {
console.log("do that");
};
};
doThisDoThat() // do this
doThisDoThat() // do that
@mkuklis
mkuklis / gist:1042935
Created June 23, 2011 16:35
classical inheritance
function inherit(C, P) {
var F = function () {};
F.prototype = P.prototype;
C.prototype = new F();
C._super = P.prototype;
C.prototype.constructor = C;
}
@mkuklis
mkuklis / ajaxify-html5.js
Created July 10, 2011 15:26 — forked from balupton/README.md
Ajaxify a Website with the HTML5 History API using History.js and ScrollTo
// https://gist.github.com/854622
(function(window,undefined){
// Prepare our Variables
var
History = window.History,
$ = window.jQuery,
document = window.document;
// Check to see if History.js is enabled for our Browser
/Users/mkuklis/.rvm/gems/ruby-1.9.2-p180@iYouVo/gems/carrierwave-0.5.4/lib/carrierwave/processing/rmagick.rb:248: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
-- control frame ----------
c:0112 p:---- s:0553 b:0553 l:000552 d:000552 CFUNC :read
c:0111 p:0054 s:0549 b:0549 l:000548 d:000548 METHOD /Users/mkuklis/.rvm/gems/ruby-1.9.2-p180@iYouVo/gems/carrierwave-0.5.4/lib/carrierwave/processing/rmagick.rb:248
c:0110 p:0011 s:0540 b:0540 l:000539 d:000539 METHOD /Users/mkuklis/.rvm/gems/ruby-1.9.2-p180@iYouVo/gems/carrierwave-0.5.4/lib/carrierwave/processing/rmagick.rb:132
c:0109 p:0015 s:0535 b:0535 l:000525 d:000534 BLOCK /Users/mkuklis/.rvm/gems/ruby-1.9.2-p180@iYouVo/gems/carrierwave-0.5.4/lib/carrierwave/uploader/processing.rb:77
c:0108 p:---- s:0531 b:0531 l:000530 d:000530 FINISH
c:0107 p:---- s:0529 b:0529 l:000528 d:000528 CFUNC :each