View ko.ext.lazy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// thanks to rniemeyer! | |
// http://www.knockmeout.net/2011/06/lazy-loading-observable-in-knockoutjs.html | |
ko.extenders.lazy = function(target, callback){ | |
var result = ko.computed({ | |
read: function(){ | |
if (!result.loaded()) callback.call(context); | |
return target(); | |
}, |
View snippet01.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// ..... | |
enqueue: function(items, get_promise, num_threads){ | |
num_threads = num_threads || 1; | |
var dfd = $.Deferred(), i = 0, num_total = items.length, num_active = 0, num_done = 0, | |
next = function(){ | |
while (num_active < num_threads && i < num_total) { | |
num_active++; | |
get_promise(items[i++]).done(function(){ |
View sections-two-levels.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$arSections = array_reduce($arResult["SECTIONS"], function($carry, $section){ | |
if (empty($section["IBLOCK_SECTION_ID"])) { // depth 1 | |
$section["LEVEL2_ITEMS"] = []; | |
$carry[$section["ID"]] = $section; | |
} else { // level |
View dist.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credits: http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates | |
function dist(a, b) { | |
const [a0, a1, b0, b1] = [...a, ...b].map(x => x / 180 * Math.PI); | |
const { acos, sin, cos } = Math; | |
return acos(sin(a0) * sin(b0) + cos(a0) * cos(b0) * cos(a1 - b1)) * 6371; | |
} |