Skip to content

Instantly share code, notes, and snippets.

Andrejs Kuzmins ostgals

Block or report user

Report or block ostgals

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ostgals
ostgals / dist.js
Created Mar 20, 2019
Spherical distance on Earth
View dist.js
// 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;
}
View sections-two-levels.php
<?
$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
@ostgals
ostgals / snippet01.js
Last active Oct 10, 2015
Snippet - Multi-thread queue with jq's promises
View snippet01.js
{
// .....
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(){
@ostgals
ostgals / ko.ext.lazy.js
Created Oct 10, 2015
Knockout - Lazy data loading into observables
View ko.ext.lazy.js
// 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();
},
You can’t perform that action at this time.