Skip to content

Instantly share code, notes, and snippets.

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

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@mkuklis
mkuklis / chain.js
Created February 27, 2011 01:11
chain
function chain() {
var cur = prev = null;
for (var i = l = arguments.length - 1; i >= 0; i--) {
prev = cur;
cur = (function(params) {
return function() {
for (var param in params) {
this[param] = params[param];
}
}
function Foo() {};
Foo.prototype = {};
var foo = new Foo();
foo.__proto__ == Foo.prototype; // true
@mkuklis
mkuklis / gist:959363
Created May 6, 2011 17:16
prototype, __proto__ & constructor in JS
var Foo1 = function() {};
var Foo2 = function() {};
var foo1 = new Foo1();
console.log(foo1.constructor == Foo1.prototype.constructor) // true
console.log(Foo1.prototype.constructor == Foo1) // true
console.log(foo1.constructor == Foo1) // true
console.log(foo1.constructor == foo1.__proto__.constructor) // true
console.log(foo1.__proto__.constructor == Foo1) // true
@mkuklis
mkuklis / gist:997928
Created May 29, 2011 16:38
JavaScript passed by value or reference
// primitives are passed by value
var a = 4;
function fn1(val) {
val = 5;
}
fn1(a);
alert(a) // still 4
// objects are passed by reference
var o = {a: 4};
@mkuklis
mkuklis / gist:1002898
Created June 1, 2011 18:06
TINYeditor
var editor = new TINY.editor.edit('editor', {
id: "editor",
width: 400,
height:200,
cssclass:'te',
controlclass:'tecontrol',
rowclass:'teheader',
dividerclass:'tedivider',
controls:['bold','italic','link','unlink','image','orderedlist','unorderedlist','undo','redo'],
footer:false,
@mkuklis
mkuklis / gist:1011477
Created June 7, 2011 01:13
JavaScript debounce
function debounce(fn, wait) {
var timeout = null;
return function () {
clearTimeout(timeout);
var args = arguments;
var ctx = this;
timeout = setTimeout(function () {
fn.apply(ctx, args);
}, wait);
}
@mkuklis
mkuklis / gist:1011501
Created June 7, 2011 01:25
JavaScript Hoisting
//1. variable declaration:
// declaration
function foo() {
return true;
var x = 1;
}
// interpretation
funciton foo() {
@mkuklis
mkuklis / gist:1012380
Created June 7, 2011 14:43
eq to any in JavaScript
function eqToAny (el /*, args */) {
var args = [].slice.call(arguments, 1);
if (args.length == 0) return false;
for (var i = 0, l = args.length; i < l; i++) {
if (el === args[i]) {
return true;
}
}
return false;
}
@mkuklis
mkuklis / gist:1021799
Created June 12, 2011 17:38
exception from jruby when running warbler
# jruby 1.6.2 (ruby-1.9.2-p136) (2011-05-23 e2ea975) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]
Michal:rice-on-rails mkuklis$ bundle exec warble config --trace
warble aborted!
stack level too deep
org/jruby/RubyArray.java:1602:in `each'
/Users/mkuklis/.rvm/gems/jruby-1.6.2@rice-on-rails/gems/railties-3.0.8/lib/rails/plugin.rb:51:in `load_deprecated_tasks'
/Users/mkuklis/.rvm/gems/jruby-1.6.2@rice-on-rails/gems/railties-3.0.8/lib/rails/plugin.rb:44:in `load_tasks'
/Users/mkuklis/.rvm/gems/jruby-1.6.2@rice-on-rails/gems/railties-3.0.8/lib/rails/application.rb:140:in `load_tasks'
org/jruby/RubyArray.java:1602:in `each'