Skip to content

Instantly share code, notes, and snippets.

@fonzerelly
fonzerelly / high_order_classes_01
Last active August 29, 2015 13:56
A lightweight constructor for jLayout-Compunents and containers.
var _createJLayoutWrapper = function (handlePosition, predicate, getSize) {
var wrapper = {
bounds : function (value) {
if (value) {
handlePosition(value);
}
return getSize();
},
isVisible : predicate,
insets : function () {
var complexHandlePosition = function (a, b, c, d, bounds) {
...
};
//a, b are available in aVal, bVal
var easierHandlePosition = _.partial(
complexHandlePosition,
aVal,
bVal
);
@fonzerelly
fonzerelly / high_order_classes_03
Last active August 29, 2015 13:56
_.constant usage
var complexPredicate = function (a, b, c) {
...
};
//a, b, c are available in aVal, bVal, cVal
var precalculatedPredicate = _constant(
complexPredicate(
aVal,
bVal,
cVal
var myJLayoutWrapper = _createJLayoutWrapper(
trivialHandlePosition,
precalcuatedPredicate,
_.noop //not interessted in putting in a valid size
);
@fonzerelly
fonzerelly / get_partialRight_right_01.js
Last active December 30, 2015 07:29
simple example of _.partialRight
var books = [
{
name: "Little Miss Sunshine",
numberOfPages: 32
},
{
name: "Mr. Strong",
numberOfPages: 36
},
{
@fonzerelly
fonzerelly / get_partialRight_right_04.js
Last active December 30, 2015 08:19
solution: a closure, that cuts of all surplus parameters
_.mixin(
{
"preserveCallersFirstNParams" : function (func, n) {
n = n || 0;
return function () {
return func.apply(this, Array.prototype.slice.call(arguments, 0, n));
};
}
);
var setTimeout,
clearTimeout,
setInterval,
clearInterval,
endAllTimers;
(function () {
var timer = new java.util.Timer();
var counter = 1;
var ids = {};
TextReporter.prototype = new jasmine.Reporter();
TextReporter.prototype.onRunnerFinished = function (callback) {
this.callbackEnd = callback;
};
TextReporter.prototype.reportRunnerResults = function (runner) {
// When all the spec are finished //
var result = runner.results();
@fonzerelly
fonzerelly / jasmine_on_rhino_03
Created January 19, 2014 23:21
Rhino based SpecRunner for jasmine
//Imported by Rhino on command shell
/*global load, print*/
load("lib/Timer.js");
/*global endAllTimers*/
load("lib/TextReporter.js");
/*global TextReporter*/
load("lib/jasmine-1.3.0/jasmine.js");
/*global jasmine*/
@fonzerelly
fonzerelly / get_partialRight_right_03.js
Last active September 2, 2016 22:15
reason of missbehaviour
//expected call for book[0]:
_.result(books[0], "numberOfPages");
//evaluated call:
_.result(books[0], 0, books, "numberOfPages");
//which means effectivly
_.result(books[0], 0);